#include <bits/stdc++.h>
int p[2005], s[2005], pos[2005], a[2000005], b[2000005];
int main() {
  int n, i, j, t, flag = 1, ans = 0, k = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &t);
    p[i] = t;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &t);
    s[i] = t;
    pos[t] = i;
  }
  while (flag) {
    flag = 0;
    for (i = 1; i <= n; i++) {
      if (pos[p[i]] == i)
        continue;
      else
        flag = 1;
      for (j = i + 1; j <= pos[p[i]] && j <= n; j++) {
        if (pos[p[j]] <= i) {
          ans += j - i;
          a[k] = i;
          b[k] = j;
          k++;
          p[i] += p[j];
          p[j] = p[i] - p[j];
          p[i] = p[i] - p[j];
        }
      }
    }
  }
  printf("%d\n%d\n", ans, k);
  for (i = 0; i < k; i++) printf("%d %d\n", a[i], b[i]);
}
