#include <bits/stdc++.h>
using namespace std;
int n, x, tot;
long long sum;
const int maxn = 2001;
int a[maxn], b[maxn], ans[maxn * 1000][2];
bool check() {
  for (int i = (1); i <= (n); i++)
    if (b[i] != i) return true;
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &b[i]);
  }
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &x);
    a[x] = i;
  }
  for (int i = (1); i <= (n); i++) {
    b[i] = a[b[i]];
    sum += max(b[i] - i, 0);
  }
  printf("%I64d\n", sum);
  for (int i = (1); i <= (n); i++) a[b[i]] = i;
  for (int i = (1); i <= (n); i++) {
    if (b[i] != i) {
      int t = a[i];
      while (t > i) {
        for (int j = (t - 1); j >= (1); j--) {
          if (b[j] >= t) {
            a[b[t]] = j;
            a[b[j]] = t;
            swap(b[t], b[j]);
            tot++;
            ans[tot][0] = t;
            ans[tot][1] = j;
            t = j;
            break;
          }
        }
      }
    }
  }
  printf("%d\n", tot);
  for (int i = (1); i <= (tot); i++) {
    printf("%d %d\n", ans[i][0], ans[i][1]);
  }
  return 0;
}
