#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
pair<int, int> ar1[2100];
int ar2[2100];
int n, x;
long long anss = 0;
void findPlace(int i);
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    ar1[i].first = x;
  }
  for (int i = 1; i <= n; i++) {
    cin >> ar2[i];
    for (int j = 1; j <= n; j++)
      if (ar1[j].first == ar2[i]) {
        ar1[j].second = i;
        break;
      }
  }
  for (int i = 1; i <= n; i++)
    while (ar1[i].first != ar2[i]) findPlace(i);
  cout << anss << endl;
  cout << ans.size() << endl;
  for (vector<pair<int, int> >::iterator i = ans.begin(); i != ans.end(); i++)
    printf("%d %d\n", (*i).first, (*i).second);
  cin >> n;
  return 0;
}
void findPlace(int pos) {
  int dest = ar1[pos].second, curPos = pos;
  for (int i = pos + 1; i <= dest; i++) {
    if (ar1[i].second <= curPos) {
      swap(ar1[i], ar1[curPos]);
      ans.push_back(make_pair(i, curPos));
      anss += (i - curPos);
      curPos = i;
    } else if (ar1[i].second > i) {
      findPlace(i);
      i--;
    }
  }
}
