#include <bits/stdc++.h>
using namespace std;
void RI() {}
template <typename... T>
void RI(int& head, T&... tail) {
  scanf("%d", &head);
  RI(tail...);
}
mt19937 rng(0x5EED);
int randint(int lb, int ub) {
  return uniform_int_distribution<int>(lb, ub)(rng);
}
int N, x[2005], y[2005], at[2005];
int cost;
vector<pair<int, int> > ops;
void swp(int a, int b) {
  cost += abs(a - b);
  ops.push_back({a, b});
  swap(x[a], x[b]);
  at[x[a]] = a;
  at[x[b]] = b;
}
int main(int argc, char** argv) {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= N; i++) {
    cin >> y[i];
    at[y[i]] = i;
  }
  for (int i = 1; i <= N; i++) {
    x[i] = at[x[i]];
  }
  int cost2 = 0;
  for (int i = 1; i <= N; i++) {
    at[x[i]] = i;
    cost2 += abs(i - x[i]);
  }
  for (int i = 1; i <= N; i++) {
    int p = at[i];
    if (p == i) continue;
    for (int j = p - 1; j > i; j--) {
      if (x[j] >= p) {
        swp(p, j);
        p = j;
      }
    }
    swp(p, i);
  }
  cout << cost << "\n";
  cout << ops.size() << "\n";
  for (const auto& it : ops) {
    cout << it.first << " " << it.second << "\n";
  }
  return 0;
}
