#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 500;
int n, a[N], b[N], pos[N];
int tn;
pair<int, int> opt[N];
int abs1(int x) { return x >= 0 ? x : -x; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", b + i);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) pos[a[i]] = i;
  for (int i = 1; i <= n; i++) b[i] = pos[b[i]];
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += abs1(b[i] - i);
  cout << ans / 2 << endl;
  for (int i = n; i >= 1; i--) {
    if (b[i] <= i) continue;
    int u = i;
    int r = b[i];
    for (int j = i + 1; j <= r; j++)
      if (b[j] <= u) opt[++tn] = make_pair(u, j), swap(b[u], b[j]), u = j;
  }
  printf("%d\n", tn);
  for (int i = 1; i <= tn; i++) printf("%d %d\n", opt[i].first, opt[i].second);
}
