#include <bits/stdc++.h>
using namespace std;
long long MOD = int(1e9) + 7;
int debug = 0;
const int N = int(2e3) + 5;
using namespace std;
int a[N], b[N], p[N];
int main() {
  int i, j, n, t;
  ios::sync_with_stdio(false);
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  int ans = 0;
  vector<pair<int, int> > moves;
  for (i = 0; i < n; i++) p[a[i]] = i;
  for (i = 0; i < n; i++) {
    int pos = -1;
    for (j = 0; j < n; j++)
      if (debug)
        cerr << "j"
             << ": " << j << " | "
             << "b[j]"
             << ": " << b[j] << endl;
    ;
    for (j = 0; j < n; j++)
      if (p[b[j]] == i) pos = j;
    if (j == i) continue;
    if (debug)
      cerr << "pos"
           << ": " << pos << " | "
           << "i"
           << ": " << i << endl;
    ;
    int cur = pos;
    for (j = pos - 1; j >= i; j--) {
      if (p[b[j]] >= cur) {
        ans += cur - j;
        moves.push_back(make_pair(j, cur));
        b[cur] = b[j];
        b[j] = i;
        cur = j;
      }
    }
  }
  cout << ans << "\n";
  reverse(moves.begin(), moves.end());
  cout << moves.size() << "\n";
  for (i = 0; i < moves.size(); i++)
    cout << moves[i].second + 1 << " " << moves[i].first + 1 << "\n";
}
