#include <bits/stdc++.h>
using namespace std;
const int N = 2035;
int n, A[N], B[N], pos[N], trans[N], ans, cnt, x[N * N], y[N * N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &B[i]), trans[B[i]] = i;
  for (int i = 1; i <= n; i++) A[i] = trans[A[i]], pos[A[i]] = i;
  for (int i = n; i >= 1; i--) {
    int p = pos[i];
    if (p == i) continue;
    for (int j = p; j <= i; j++)
      if (A[j] <= p) {
        ans += j - p, cnt++;
        x[cnt] = p, y[cnt] = j;
        swap(pos[A[j]], pos[A[p]]), swap(A[j], A[p]), p = j;
      }
  }
  printf("%d\n%d\n", ans, cnt);
  for (int i = 1; i <= cnt; i++) printf("%d %d\n", x[i], y[i]);
  return 0;
}
