#include <bits/stdc++.h>
using namespace std;
const int maxn = 2003;
int mp[maxn];
int b[maxn], p[maxn];
int x[maxn * 100], y[maxn * 100];
int n;
int main() {
  int i, j, k, a, cnt = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    mp[a] = i;
  }
  for (i = 1; i <= n; i++) b[i] = mp[p[i]];
  int res = 0;
  for (i = 1; i <= n; i++) {
    for (k = i;; k++)
      if (b[k] == i) break;
    while (i != k) {
      for (j = i; j <= k; j++) {
        if (b[j] >= k) {
          swap(b[j], b[k]);
          x[cnt] = j;
          y[cnt++] = k;
          res += k - j;
          k = j;
        }
      }
    }
  }
  printf("%d\n%d\n", res, cnt);
  for (i = 0; i < cnt; i++) printf("%d %d\n", x[i], y[i]);
}
