#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
int a[N], pa[N], pb[N], b[N];
vector<pair<int, int> > ans;
int n, dis = 0;
void SWAP(int x, int y) {
  ans.push_back(make_pair(x, y));
  dis += abs(y - x);
  int A = a[x], B = a[y];
  swap(a[x], a[y]);
  pa[A] = y;
  pa[B] = x;
}
void get(int p[], int q[]) {
  for (int i = 0; i < n; i++) {
    scanf("%d", p + i);
    q[--p[i]] = i;
  }
}
int main() {
  scanf("%d", &n);
  get(a, pa);
  get(b, pb);
  for (int i = 0; i < n; i++) {
    int x = b[i];
    for (int j = pa[x] - 1; j >= i; j--)
      if (pb[a[j]] >= pa[x]) SWAP(j, pa[x]);
  }
  printf("%d\n%d\n", dis, ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
}
