#include <bits/stdc++.h>
using namespace std;
int n, a[2003], b[2003], d[2003], sol;
vector<pair<int, int> > all;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    d[b[i]] = i;
  }
  while (1) {
    int cur = -1;
    for (int i = 0; i < n; i++) {
      if (d[a[i]] < i) {
        cur = i;
        break;
      }
    }
    if (cur == -1) break;
    for (int i = cur - 1; i >= 0; i--) {
      if (d[a[i]] > i) {
        swap(a[i], a[cur]);
        all.push_back({i + 1, cur + 1});
        sol += cur - i;
        cur = i;
        if (cur == d[a[cur]]) break;
      }
    }
  }
  printf("%d\n%d\n", sol, all.size());
  for (auto u : all) printf("%d %d\n", u.first, u.second);
  return 0;
}
