#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 5000;
int n;
int a[maxn], b[maxn];
int f[maxn];
vector<pair<int, int> > q;
void exchange(int x, int y) {
  swap(a[x], a[y]);
  swap(f[x], f[y]);
  q.push_back(make_pair(x, y));
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int j = 1; j <= n; j++) cin >> b[j];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (b[j] == a[i]) {
        f[i] = j;
      }
  }
  for (int i = 1; i <= n; i++) {
    ans += abs(f[i] - i);
  }
  int i = 1;
  while (i < n) {
    int g = i;
    if (a[i] != b[i]) {
      for (int j = i + 1; j <= n; j++)
        if (f[j] == i) {
          g = j;
          break;
        }
      for (int j = i; j < g; j++)
        if (f[j] >= g) {
          exchange(j, g);
          break;
        }
    }
    if (a[i] == b[i]) i++;
  }
  int len = q.size();
  printf("%d\n%d\n", ans / 2, len);
  for (int i = 0; i < len; i++) printf("%d %d\n", q[i].first, q[i].second);
  return 0;
}
