#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2010;
int N;
int P1[NMAX], P2[NMAX], pos[NMAX];
vector<pair<int, int> > answer;
int main() {
  ios_base::sync_with_stdio(false);
  int i, j;
  cin >> N;
  for (i = 1; i <= N; ++i) cin >> P1[i];
  for (i = 1; i <= N; ++i) {
    cin >> P2[i];
    pos[P2[i]] = i;
  }
  int _answer = 0;
  for (i = 1; i <= N; ++i) {
    int p = i;
    for (j = i - 1; j >= pos[P1[p]]; --j) {
      if (pos[P1[j]] >= p) {
        swap(P1[j], P1[p]);
        answer.push_back(make_pair(p, j));
        _answer += abs(j - p);
        p = j;
      }
    }
  }
  cout << _answer << '\n' << answer.size() << '\n';
  for (const auto &it : answer) cout << it.first << ' ' << it.second << '\n';
  return 0;
}
