#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
int A[N], B[N], n, ans, pos[N], s1[N], s2[N], cnt;
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;
  for (int i = 1; i <= n; ++i) pos[A[i]] = i;
ZXY:;
  int st = 1;
  while (A[st] == st) st++;
  for (int i = st; i <= n; ++i)
    if (A[i] > i) {
      for (int j = i + 1; j <= n; ++j)
        if (A[j] <= i && j <= A[i]) {
          ans += j - i;
          s1[++cnt] = i, s2[cnt] = j;
          swap(A[i], A[j]);
          goto ZXY;
        }
    }
  cout << ans << endl << cnt << endl;
  for (int i = 1; i <= cnt; ++i) cout << s1[i] << " " << s2[i] << endl;
  return 0;
}
