#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int a[maxn], b[maxn], trans[maxn];
int s[2 * 1000010], e[2 * 1000010];
int cnt;
long long ans;
int main() {
  int n;
  ans = 0;
  cnt = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
    trans[b[i]] = i;
  }
  for (int i = 1; i <= n; ++i) {
    a[i] = trans[a[i]];
  }
  for (int i = n; i >= 1; --i) {
    if (a[i] == i) continue;
    int p;
    for (int j = 1; j <= n; ++j) {
      if (a[j] == i) {
        p = j;
        break;
      }
    }
    int j = p + 1;
    while (p != i) {
      if (a[j] <= p) {
        swap(a[p], a[j]);
        s[cnt] = j;
        e[cnt] = p;
        cnt++;
        ans += j - p;
        p = j;
      } else {
        j++;
      }
    }
  }
  printf("%I64d\n", ans);
  printf("%d\n", cnt);
  for (int i = 0; i < cnt; ++i) {
    printf("%d %d\n", s[i], e[i]);
  }
  return 0;
}
