#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
const long long inf = (long long)1e15;
const int mod = (int)1e9 + 7;
int a[N], b[N], n, pos[N];
int main() {
  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];
    a[pos[b[i]]] = i;
  }
  int answer = 0;
  vector<pair<int, int> > vec;
  for (int num = 1; num <= n; ++num) {
    int cur;
    for (int i = num; i <= n; ++i) {
      if (a[i] == num) {
        cur = i;
        break;
      }
    }
    while (cur > num) {
      for (int j = cur - 1; j >= num; --j) {
        if (a[j] >= cur) {
          swap(a[cur], a[j]);
          vec.push_back(make_pair(cur, j));
          answer += abs(cur - j);
          cur = j;
          break;
        }
      }
    }
  }
  printf("%d\n%d\n", answer, vec.size());
  for (auto x : vec) {
    printf("%d %d\n", x.first, x.second);
  }
  return 0;
}
