#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int a[maxn], b[maxn], pa[maxn], pb[maxn];
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int> > ans;
  int val = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) pa[a[i]] = i;
  for (int i = 1; i <= n; i++) pb[b[i]] = i;
  for (int i = n; i >= 2; i--) {
    int pos = pa[b[i]];
    for (int j = pos + 1; j <= i; j++) {
      if (pos >= pb[a[j]]) {
        ans.push_back(make_pair(pos, j));
        val += abs(pos - j);
        swap(pa[a[j]], pa[a[pos]]);
        swap(a[j], a[pos]);
        pos = j;
      }
    }
  }
  printf("%d\n", val);
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
}
