#include <bits/stdc++.h>
using namespace std;
int p[2020], s[2020], f[2020];
int n;
vector<pair<int, int> > ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    f[s[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    p[i] = f[p[i]];
  }
  int sum = 0;
  while (1) {
    int pos = 0;
    for (int i = 1; i <= n; i++) {
      if (p[i] != i && (!pos || p[pos] > p[i])) pos = i;
    }
    if (!pos) break;
    for (int i = pos; i >= p[pos]; i--) {
      if (p[i] >= pos) {
        ans.push_back(pair<int, int>(i, pos));
        swap(p[i], p[pos]);
        sum += abs(i - pos);
        pos = i;
      }
    }
  }
  printf("%d\n%d\n", sum, ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
}
