#include <bits/stdc++.h>
using namespace std;
int r[2001], p[2001], n;
int rmp[2001], pmp[2001];
int va[1000001], vb[1000001];
void printRP() {
  cout << endl;
  for (int i = int(0); i < int(n); i++) cout << r[i] << " ";
  cout << endl;
  for (int i = int(0); i < int(n); i++) cout << p[i] << " ";
  cout << endl << endl;
}
int main() {
  cin >> n;
  int trocas = 0, peso = 0, v = 0;
  bool ord;
  for (int i = int(0); i < int(n); i++) scanf("%d", &p[i]), pmp[p[i]] = i;
  for (int i = int(0); i < int(n); i++) scanf("%d", &r[i]), rmp[r[i]] = i;
  for (int i = int(0); i < int(n); i++) {
    int at = pmp[r[i]];
    if (r[i] != p[i])
      for (int j = pmp[r[i]] - 1; j >= rmp[r[i]]; j--) {
        if (rmp[p[j]] >= pmp[r[i]]) {
          pmp[p[at]] = j;
          pmp[p[j]] = at;
          swap(p[at], p[j]);
          trocas++;
          peso += fabs(j - at);
          va[v] = at + 1;
          vb[v] = j + 1;
          v++;
          at = j;
        }
      }
  }
  cout << peso << endl;
  cout << trocas << endl;
  for (int i = int(0); i < int(trocas); i++) {
    printf("%d %d\n", va[i], vb[i]);
  }
  return 0;
}
