#include <bits/stdc++.h>
using namespace std;
int n, cnt, a[2010], b[2010], bel[2010], ans[2010 * 2010 / 2][2];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    bel[b[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = bel[a[i]];
    cnt += abs(a[i] - i);
  }
  cnt /= 2;
  printf("%d\n", cnt);
  cnt = 0;
  for (int i = 1; i <= n; i++) bel[a[i]] = i;
  for (int i = n, now = bel[n]; i; i--, now = bel[i])
    for (int j = bel[i] + 1; j <= n; j++)
      if (a[j] <= now) {
        ans[++cnt][0] = j;
        ans[cnt][1] = now;
        swap(a[now], a[j]);
        now = j;
      }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  return 0;
}
