#include <bits/stdc++.h>
using namespace std;
const int N = 2002;
int p1[N], p2[N], to[N], n;
int op1[N * N], op2[N * N], tp = 0, ans = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", p1 + i);
  for (int i = 1; i <= n; i++) scanf("%d", p2 + i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (p2[j] == p1[i]) to[i] = j;
  }
  for (int i = n; i >= 1; i--) {
    if (to[i] > i) {
      int j = i, k = i + 1;
      for (; to[j] > j; j = k, k++) {
        while (to[k] == k) k++;
        ++tp;
        op1[tp] = j;
        op2[tp] = k;
        swap(to[j], to[k]);
        ans += k - j;
      }
    }
  }
  printf("%d\n%d\n", ans, tp);
  for (int i = 1; i <= tp; i++) {
    printf("%d %d\n", op1[i], op2[i]);
  }
  return 0;
}
