#include <bits/stdc++.h>
using namespace std;
const int mx = 2003;
int main() {
  int n, p[mx], s[mx], ans = 0;
  scanf("%d", &n);
  for (int i = (0); i < int(n); ++i) scanf("%d", p + i);
  for (int i = (0); i < int(n); ++i) {
    int a;
    scanf("%d", &a);
    s[a] = i;
  }
  for (int i = (0); i < int(n); ++i) {
    p[i] = s[p[i]];
    ans += abs(p[i] - i);
  }
  printf("%d\n", ans / 2);
  vector<pair<int, int> > svar;
  for (int i = (0); i < int(n); ++i) {
    int pos;
    for (int j = (i); j < int(n); ++j)
      if (p[j] == i) {
        pos = j;
        break;
      }
    while (pos != i) {
      for (int j = pos - 1;; --j) {
        if (p[j] >= pos) {
          svar.push_back(pair<int, int>(j, pos));
          swap(p[j], p[pos]);
          pos = j;
          break;
        }
      }
    }
  }
  printf("%d\n", (int)svar.size());
  for (pair<int, int> &p : svar) printf("%d %d\n", p.first + 1, p.second + 1);
}
