#include <bits/stdc++.h>
using namespace std;
int a[2005], b[2005], pos[2005];
vector<pair<int, int> > answer;
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    pos[x] = i;
  }
  for (i = 1; i <= n; i++) b[i] = pos[a[i]];
  long long ans = 0;
  for (int now = 1; now <= n; now++) {
    int now_pos;
    for (now_pos = now; now_pos <= n; now_pos++)
      if (b[now_pos] == now) break;
    if (now_pos == now) continue;
    for (i = now_pos - 1; i >= now; i--) {
      if (b[i] >= now_pos) {
        ans += (now_pos - i);
        swap(b[i], b[now_pos]);
        answer.push_back({i, now_pos});
        now_pos = i;
      }
    }
  }
  printf("%I64d\n%d\n", ans, answer.size());
  for (i = 0; i < answer.size(); i++)
    printf("%d %d\n", answer[i].first, answer[i].second);
  return 0;
}
