#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int p[maxn], q[maxn], mp[maxn], mq[maxn], ans, n;
vector<pair<int, int> > v;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    mp[x] = i;
    p[i] = x;
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    mq[x] = i;
    q[i] = x;
  }
  for (int i = 1; i <= n; i++) {
    int idx = mp[q[i]];
    while (idx != i) {
      for (int k = n; k >= i + 1; k--) {
        int j = q[k];
        int idx2 = mp[j];
        if (idx2 < idx) {
          swap(p[idx], p[idx2]);
          mp[p[idx]] = idx;
          mp[p[idx2]] = idx2;
          v.push_back(make_pair(idx, idx2));
          ans += idx - idx2;
          idx = idx2;
        }
      }
    }
  }
  cout << ans << endl;
  cout << (int)v.size() << endl;
  for (int i = 0; i < (int)v.size(); i++)
    cout << v[i].first << " " << v[i].second << "\n";
  return 0;
}
