#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int n;
int a[maxn], b[maxn];
vector<pair<int, int> > op;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    b[x] = i;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = b[a[i]];
  }
  int cost = 0;
  for (int i = n; i >= 1; i--) {
    int pos;
    for (int j = 1; j <= n; j++) {
      if (a[j] == i) {
        pos = j;
        break;
      }
    }
    while (pos < i) {
      int t = pos + 1;
      while (a[t] > pos) t++;
      cost += abs(pos - t);
      swap(a[pos], a[t]);
      op.push_back(pair<int, int>(pos, t));
      pos = t;
    }
  }
  cout << cost << endl;
  cout << op.size() << endl;
  for (int i = 0; i < op.size(); i++) {
    printf("%d %d\n", op[i].first, op[i].second);
  }
  return 0;
}
