#include <bits/stdc++.h>
using namespace std;
const int N = 2222;
int a[N], b[N], mp[N], pre[N];
pair<int, int> ret[2000010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    mp[b[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    a[i] = mp[a[i]];
  }
  int cost = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == i) {
      continue;
    }
    int aim = -1;
    for (int j = i; j < n; j++) {
      if (a[j] == i) {
        aim = j;
        break;
      }
    }
    pre[i] = i;
    for (int j = i + 1; j < aim; j++) {
      pre[j] = pre[j - 1];
      if (a[j] > a[pre[j]]) {
        pre[j] = j;
      }
    }
    cost += aim - i;
    for (; aim != i; aim = pre[aim - 1]) {
      ret[cnt++] = make_pair(aim + 1, pre[aim - 1] + 1);
      swap(a[aim], a[pre[aim - 1]]);
    }
  }
  cout << cost << endl << cnt << endl;
  for (int i = 0; i < cnt; i++) {
    cout << ret[i].first << " " << ret[i].second << "\n";
  }
  return 0;
}
