#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> p(n + 1);
  vector<int> ind(n + 1);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    p[i] = a;
  }
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    ind[a] = i;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += abs(i - ind[p[i]]);
  }
  cout << sum / 2 << endl;
  vector<pair<int, int> > rest;
  for (int i = 1; i <= n; i++) {
    if (ind[p[i]] < i) {
      int index = i;
      for (int j = i - 1; j >= ind[p[index]]; j--) {
        if (ind[p[j]] != j) {
          int tmp = p[index];
          p[index] = p[j];
          p[j] = tmp;
          rest.push_back(make_pair(index, j));
          index = j;
        }
      }
    }
  }
  cout << rest.size() << endl;
  for (int i = 0; i < rest.size(); i++)
    printf("%d %d\n", rest[i].first, rest[i].second);
  return 0;
}
