#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
int a[N], b[N], wz[N];
vector<pair<int, int> > vec;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    wz[b[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = wz[a[i]];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int flag, now;
    for (int j = i; j <= n; j++)
      if (a[j] == i) flag = j;
    now = flag;
    for (int j = flag - 1; j >= i; j--) {
      if (a[j] >= now) {
        ans += now - j;
        swap(a[j], a[now]);
        vec.push_back(make_pair(j, now));
        now = j;
      }
    }
  }
  cout << ans << endl;
  int len = (int)vec.size();
  cout << len << endl;
  for (int i = 0; i < len; i++) printf("%d %d\n", vec[i].first, vec[i].second);
  return 0;
}
