#include <bits/stdc++.h>
using namespace std;
int a[100010];
pair<int, int> b[100010];
vector<pair<int, int> > out;
int main() {
  int n, i, j;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (i = 0; i < n; ++i) {
    scanf("%d", &b[i].first);
    b[i].second = i;
  }
  sort(b, b + n);
  for (i = 0; i < n; ++i) a[i] = b[a[i] - 1].second;
  long long ans = 0;
  for (i = 0; i < n; ++i) ans = ans + abs(a[i] - i);
  ans >>= 1;
  printf("%lld\n", ans);
  for (i = 0; i < n; ++i) {
    int pos;
    for (j = i; j < n; ++j)
      if (a[j] == i) break;
    pos = j;
    for (j = j - 1; j >= i; --j) {
      if (a[j] >= pos) {
        out.push_back(make_pair(j, pos));
        swap(a[j], a[pos]);
        pos = j;
      }
    }
  }
  printf("%d\n", (int)out.size());
  for (i = 0; i < out.size(); ++i)
    printf("%d %d\n", out[i].first + 1, out[i].second + 1);
}
