#include <bits/stdc++.h>
using namespace std;
int a[2010], b[2010];
int pos[2010];
struct point {
  int x, y;
} P[2 * 1100000];
int xx, cost;
int solve(int *a, int n) {
  if (n == 1) return 0;
  int x;
  for (int i = 1; i <= n; i++) {
    if (a[i] == n) {
      x = i;
      break;
    }
  }
  int yy = 0;
  for (int i = x + 1; i <= n; i++) {
    if (a[i] <= x) {
      P[xx].x = x;
      P[xx].y = i;
      xx++;
      swap(a[x], a[i]);
      yy += abs(x - i);
      x = i;
    }
  }
  return yy + solve(a, n - 1);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    int c;
    cin >> c;
    b[c] = i;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = b[a[i]];
  }
  cost = solve(a, n);
  printf("%d\n%d\n", cost, xx);
  for (int i = 0; i < xx; i++) {
    printf("%d %d\n", P[i].x, P[i].y);
  }
  return 0;
}
