#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000 + 7;
int a[MAXN], pos[MAXN];
vector<pair<int, int> > res;
int main() {
  int n, d;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d);
    pos[d] = i;
  }
  int cnt = 0, notok = 0;
  long long cost = 0;
  for (int i = 1; i <= n; i++) {
    if (pos[a[i]] != i) notok++;
  }
  while (notok) {
    for (int i = 1; i <= n; i++) {
      if (pos[a[i]] > i) {
        for (int j = i + 1; j <= pos[a[i]]; j++) {
          if (pos[a[j]] <= i) {
            swap(a[i], a[j]);
            cnt++;
            cost += (j - i);
            if (pos[a[i]] == i) notok--;
            if (pos[a[j]] == j) notok--;
            res.push_back({i, j});
            break;
          }
        }
      }
    }
  }
  cout << cost << endl;
  cout << cnt << endl;
  for (int i = 0; i < res.size(); i++) {
    printf("%d %d\n", res[i].first, res[i].second);
  }
  return 0;
}
