#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
int n, p[N], s[N], a[N];
long long res = 0;
vector<pair<int, int> > ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (int)n; ++i) scanf("%d", p + i);
  for (int i = 0; i < (int)n; ++i) scanf("%d", s + i);
  map<int, int> pos;
  for (int i = 0; i < (int)n; ++i) pos[s[i]] = i;
  for (int i = 0; i < (int)n; ++i) a[i] = pos[p[i]];
  while (true) {
    for (int i = 0; i < (int)n; ++i)
      if (i < a[i]) {
        for (int j = a[i]; j > i; --j)
          if (a[j] <= i) {
            res += j - i;
            ans.push_back(make_pair(i, j));
            swap(a[i], a[j]);
            break;
          }
      }
    if (is_sorted(a, a + n)) break;
  }
  printf("%I64d\n%d\n", res, (int)ans.size());
  for (auto &pr : ans) printf("%d %d\n", pr.first + 1, pr.second + 1);
}
