#include <bits/stdc++.h>
using namespace std;
const int N = 2333;
int a[N], b[N], n, pos[N];
vector<pair<int, int> > vc;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", b + i);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i), pos[a[i]] = i;
  int d = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (a[i] == b[j]) d += (i > j) ? i - j : j - i;
  printf("%d\n", d / 2);
  for (int i = 1; i <= n; ++i) {
    int x = 0;
    for (int j = i; j <= n && !x; ++j)
      if (a[i] == b[j]) x = j;
    for (int j = x - 1; j >= i; --j)
      if (pos[b[j]] >= x) vc.emplace_back(j, x), swap(b[j], b[x]), x = j;
  }
  printf("%d\n", vc.size());
  for (auto it : vc) printf("%d %d\n", it.first, it.second);
  return 0;
}
