#include <bits/stdc++.h>
using namespace std;
int a[2005], b[2005], at[2005];
int ans, anss[2000005], anss2[2000005];
int n, now, co;
int main(int argc, char *argv[]) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    at[b[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      for (int j = i + 1; j < n; j++) {
        if (a[j] == b[i]) {
          now = j;
          break;
        }
      }
      for (int j = now - 1; j >= i; j--) {
        if (at[a[j]] >= now) {
          ans += (now - j);
          anss[co] = now + 1;
          anss2[co] = j + 1;
          co++;
          a[j] ^= a[now];
          a[now] ^= a[j];
          a[j] ^= a[now];
          now = j;
        }
      }
    }
  }
  printf("%d\n%d\n", ans, co);
  for (int i = 0; i < co; i++) {
    printf("%d %d\n", anss[i], anss2[i]);
  }
  return 0;
}
