#include <bits/stdc++.h>
using namespace std;
int N;
int p[2003];
int s[2003];
int sinv[2003];
int coins;
int swaps;
vector<pair<int, int>> ans;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= N; i++) scanf("%d", &s[i]);
  for (int i = 1; i <= N; i++) sinv[s[i]] = i;
  for (int i = 1; i <= N; i++) p[i] = sinv[p[i]];
  for (int n = N; n >= 2; n--) {
    int i = 1;
    while (p[i] != n) i++;
    while (i < n) {
      int j = i + 1;
      while (!(p[j] <= i)) j++;
      swap(p[i], p[j]);
      coins += abs(i - j);
      swaps++;
      ans.push_back(make_pair(i, j));
      i = j;
    }
  }
  printf("%d\n", coins);
  printf("%d\n", swaps);
  for (auto a : ans) printf("%d %d\n", a.first, a.second);
  return 0;
}
