#include <bits/stdc++.h>
using namespace std;
long long t, n, k, x, b, a[20000], m, p[200000], s[20000], cost;
pair<int, int> ans[300000];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[x] = i;
  }
  for (int i = 1; i <= n; i++) {
    p[i] = -i + a[s[i]];
  }
  for (int l = 1; l <= 2000; l++)
    for (int i = 1; i < n; i++)
      if (p[i] > 0)
        for (int j = i + 1; j <= p[i] + i; j++)
          if (p[i] > 0 && p[j] < 0 && p[i] >= j - i && p[j] <= i - j) {
            k++;
            ans[k].first = i;
            ans[k].second = j;
            cost += abs(i - j);
            p[i] -= j - i;
            p[j] += j - i;
            swap(p[i], p[j]);
            i = j;
            j = 1000000;
          }
  cout << cost << endl;
  cout << k << endl;
  for (int i = 1; i <= k; i++)
    cout << ans[i].first << " " << ans[i].second << endl;
}
