#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 333;
const long long linf = 1e18 + inf;
const int N = 2000 + 5;
int n;
int a[N], w[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    w[x] = i;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = w[a[i]];
  }
  for (int i = 1; i <= n; i++) {
    w[a[i]] = i;
  }
  int ans = 0;
  vector<pair<int, int> > v;
  for (int i = 1; i <= n; i++) {
    int x = w[i];
    assert(a[x] <= x);
    ans += x - a[x];
    for (int i = x - 1; i >= a[x]; i--) {
      if (a[i] >= x) {
        v.push_back(pair<int, int>(i, x));
        swap(a[i], a[x]);
        swap(w[a[i]], w[a[x]]);
        x = i;
      }
    }
  }
  printf("%d\n", ans);
  printf("%d\n", v.size());
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) {
    int x = it->first;
    int y = it->second;
    printf("%d %d\n", x, y);
  }
  return 0;
}
