#include <bits/stdc++.h>
using namespace std;
int N;
int A[2005], B[2005];
int pos[2005], goal[2005];
vector<pair<int, int> > step;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    pos[A[i]] = i;
  }
  for (int i = 1; i <= N; i++) {
    cin >> B[i];
    goal[B[i]] = i;
  }
  int ans = 0, ok = 1;
  while (ok) {
    ok = 0;
    int idx = 0;
    for (int i = 1; i <= N; i++) {
      if (goal[A[idx]] < i) idx = 0;
      if (goal[A[i]] > goal[A[idx]] && goal[A[i]] > i) idx = i;
      if (idx != 0 && idx != i && goal[A[i]] <= idx) {
        int now = idx > i ? idx - i : i - idx;
        ans += now;
        pos[A[idx]] = i;
        pos[A[i]] = idx;
        swap(A[i], A[idx]);
        step.emplace_back(i, idx);
        ok = 1;
      }
    }
  }
  cout << ans << "\n";
  cout << step.size() << '\n';
  for (pair<int, int> now : step) {
    cout << now.first << " " << now.second << "\n";
  }
  cin >> N;
}
