#include <bits/stdc++.h>
using namespace std;
int g1[3000], g2[3000], h[3000];
int x[3000000], y[3000000];
int i, j, k, n, s, t, z;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &g1[i]);
  for (i = 1; i <= n; i++) scanf("%d", &g2[i]);
  for (i = 1; i <= n; i++) h[g2[i]] = i;
  for (i = n; i > 0; i--)
    if (h[g1[i]] > i) {
      t = h[g1[i]], s = s + t - i;
      for (j = i, k = i; j <= t; j++)
        if (h[g1[j]] <= k) {
          z++, x[z] = j, y[z] = k;
          swap(g1[j], g1[k]), k = j;
        }
    }
  printf("%d\n%d\n", s, z);
  for (i = 1; i <= z; i++) printf("%d %d\n", x[i], y[i]);
  return 0;
}
