#include <bits/stdc++.h>
using namespace std;
int n, m;
int A[5006], B[5006], push_back[5006], pos[5006];
void solve() {
  cin >> n;
  for (int i = (1), iend = (n); i <= iend; ++i) scanf("%d", A + i);
  for (int i = (1), iend = (n); i <= iend; ++i)
    scanf("%d", B + i), push_back[B[i]] = i;
  for (int i = (1), iend = (n); i <= iend; ++i)
    A[i] = push_back[A[i]], pos[A[i]] = i;
  int as = 0;
  for (int i = (1), iend = (n); i <= iend; ++i) as += abs(i - A[i]);
  vector<pair<int, int> > op;
  for (int i = (1), iend = (n); i <= iend; ++i) {
    int p = pos[i];
    for (int j = (p - 1), jend = (i); j >= jend; --j) {
      if (A[j] >= p) op.emplace_back(make_pair(j, p)), swap(A[j], A[p]), p = j;
    }
  }
  cout << as / 2 << endl;
  cout << op.size() << endl;
  for (auto [a, b] : op) printf("%d %d\n", a, b);
}
signed main() { solve(); }
