#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3;
const int maxm = 2e6;
int a[maxn + 10], b[maxn + 10], pos[maxn + 10];
int ans1[maxm + 10], ans2[maxm + 10];
int main() {
  int n, ans = 0, cnt = 0;
  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]), pos[b[i]] = i;
  for (int i = 1; i <= n; i++) {
    int now = b[i];
    int now_pos;
    for (int j = i; j <= n; j++)
      if (a[j] == now) now_pos = j;
    for (int j = now_pos - 1; j >= i; j--)
      if (pos[a[j]] >= now_pos) {
        ans += now_pos - j;
        cnt++;
        ans1[cnt] = now_pos, ans2[cnt] = j;
        swap(a[j], a[now_pos]), now_pos = j;
      }
  }
  printf("%d\n", ans);
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) printf("%d %d\n", ans1[i], ans2[i]);
  return 0;
}
