#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > V;
int n, sa[2002], sb[2002], pa[2002], pb[2002], ans = 0, sz = 0;
void sw(int i, int j) {
  swap(pa[sa[i]], pa[sa[j]]);
  swap(sa[i], sa[j]);
  ans += abs(j - i);
  sz++;
  V.push_back(make_pair(i, j));
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &sa[i]);
    pa[sa[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &sb[i]);
    pb[sb[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (sa[i] == sb[i]) continue;
    int sp;
    for (int j = i; j <= n; j++) {
      if (sa[j] == sb[i]) {
        sp = j;
        break;
      }
    }
    for (int j = sp - 1; j >= i; j--) {
      if (pb[sa[j]] >= sp) {
        sw(j, sp);
        sp = j;
      }
    }
  }
  printf("%d\n%d\n", ans, sz);
  for (int i = 0; i <= sz - 1; i++) printf("%d %d\n", V[i].first, V[i].second);
  return 0;
}
