#include <bits/stdc++.h>
using namespace std;
int n, cost = 0, k = 0;
int p[2005], q[2005];
int d[2005];
int cc[2000005][2];
int sum = 0;
int main() {
  int a;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &a), q[a] = i;
  for (int i = 1; i <= n; i++) d[i] = q[p[i]];
  for (int i = 1; i <= n; i++) p[d[i]] = i;
  for (int i = 1; i <= n; i++) sum += abs(d[i] - i);
  for (int i = 1; i <= n; i++) {
    int pos = p[i];
    for (int j = pos - 1; j >= i; j--) {
      if (d[j] >= pos) {
        cost += pos - j;
        int temp;
        temp = d[pos];
        d[pos] = d[j];
        d[j] = temp;
        p[d[pos]] = pos;
        p[d[j]] = j;
        cc[++k][0] = pos;
        cc[k][1] = j;
        pos = j;
      }
    }
  }
  printf("%d\n", cost);
  printf("%d\n", k);
  for (int i = 1; i <= k; i++) printf("%d %d\n", cc[i][0], cc[i][1]);
  return 0;
}
