#include <bits/stdc++.h>
using namespace std;
int N, K, P[2100], S[2100], ans[(int)4e6 + 100], cost = 0;
int abs(int a) { return a > 0 ? a : -a; }
void swap(int i, int j) {
  cost += abs(i - j);
  ans[++K] = i;
  ans[++K] = j;
  P[i] ^= P[j];
  P[j] ^= P[i];
  P[i] ^= P[j];
}
stack<int> box;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", P + i);
  for (int i = 1; i <= N; i++) {
    int tmp;
    scanf("%d", &tmp);
    S[tmp] = i;
  }
  for (int i = 1; i <= N; i++) P[i] = S[P[i]];
  for (int i = 1; i <= N; i++) {
    if (P[i] > i) box.push(i);
    int pos = i;
    while (box.size() && P[pos] <= box.top() && P[box.top()] >= pos) {
      swap(box.top(), pos);
      i = pos - 1;
      pos = box.top();
      box.pop();
    }
  }
  printf("%d\n%d\n", cost, K >> 1);
  for (int i = 1; i <= K; i++) printf("%d%c", ans[i], i & 1 ? 32 : 10);
}
