#include <bits/stdc++.h>
using namespace std;
const int N = 2008;
int a[N], b[N], tot, s;
struct aa {
  int x, y;
} d[N * N];
int absx(int x) {
  if (x < 0) return -x;
  return x;
}
int main(void) {
  int i, j, k, n, p;
  aa t;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", a + i);
  for (i = 1; i <= n; i++) {
    scanf("%d", &k);
    b[k] = i;
  }
  for (i = 1; i <= n; i++) a[i] = b[a[i]];
  tot = s = 0;
  for (i = 1; i <= n; i++)
    if (a[i] != i) {
      for (j = i; a[j] != i; j++)
        ;
      while (a[i] != i) {
        for (k = j - 1; a[k] < j; k--)
          ;
        s += j - k;
        t.x = j;
        t.y = k;
        d[++tot] = t;
        p = a[j];
        a[j] = a[k];
        a[k] = p;
        j = k;
      }
    }
  printf("%d\n%d\n", s, tot);
  for (i = 1; i <= tot; i++) printf("%d %d\n", d[i].x, d[i].y);
  return 0;
}
