#include <bits/stdc++.h>
using namespace std;
int a[2002], b[2002], pozinb[2002];
int x[1000002], y[1000002];
int cost = 0;
int cont = 0;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    pozinb[b[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    int mark;
    for (int j = 1; j <= n; j++) {
      if (a[j] == b[i]) {
        mark = j;
      }
    }
    int p = mark;
    for (int j = mark - 1; j >= i; j--) {
      if (pozinb[a[j]] >= p) {
        cost += p - j;
        cont++;
        x[cont] = j;
        y[cont] = p;
        swap(a[j], a[p]);
        p = j;
      }
    }
  }
  cout << cost << '\n' << cont << '\n';
  for (int i = 1; i <= cont; i++) {
    cout << x[i] << " " << y[i] << '\n';
  }
  return 0;
}
