#include <bits/stdc++.h>
using namespace std;
int b, n, k, i, h, ans, a[2005], M[2005];
struct nod {
  int x, y;
} cnt[2005 * 2005];
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), M[b] = i;
  for (int i = 1; i <= n; i++) a[i] = M[a[i]];
  for (int i = 1; i <= n; i++) {
    if (a[i] == i) continue;
    for (k = i; k <= n; k++)
      if (a[k] == i) break;
    for (int j = k - 1; j >= i; j--)
      if (a[j] >= k) {
        swap(a[j], a[k]);
        cnt[++ans] = (nod){j, k};
        h += k - j;
        k = j;
      }
  }
  printf("%d\n%d\n", h, ans);
  for (int i = 1; i <= ans; i++) printf("%d %d\n", cnt[i].x, cnt[i].y);
  return 0;
}
