#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int a[maxn], b[maxn], u[maxn * maxn], v[maxn * maxn];
int main() {
  int n, x, ans = 0, num = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[x] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", b + i);
    b[i] = a[b[i]];
  }
  for (int i = 1; i <= n; i++) ans += abs(b[i] - i);
  printf("%d\n", ans / 2);
  for (int i = n; i >= 1; i--) {
    int pos;
    for (int j = 1; j <= n; j++)
      if (b[j] == i) {
        pos = j;
        break;
      }
    for (int j = pos + 1; j <= n; j++) {
      if (b[j] <= pos) {
        u[num] = pos;
        v[num++] = j;
        swap(b[pos], b[j]);
        pos = j;
      }
    }
  }
  printf("%d\n", num);
  for (int i = num - 1; i >= 0; i--) {
    printf("%d %d\n", u[i], v[i]);
  }
  return 0;
}
