#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int n, a[maxn], b[maxn], p[maxn];
int A[2000005], B[2000005], top, ans;
int mabs(int x) { return x < 0 ? -x : x; }
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    p[b[i]] = i;
  }
  top = ans = 0;
  for (k = 0; k < n; k++) {
    if (a[k] == b[k]) continue;
    for (i = k + 1; i < n; i++)
      if (a[i] == b[k]) break;
    ans += i - k;
    for (j = i - 1; j >= k; j--) {
      if (p[a[j]] >= i) {
        swap(a[i], a[j]);
        A[top] = i + 1, B[top] = j + 1, top++;
        i = j;
      }
    }
  }
  printf("%d\n%d\n", ans, top);
  for (i = 0; i < top; i++) printf("%d %d\n", A[i], B[i]);
  return 0;
}
