#include <bits/stdc++.h>
using namespace std;
const int delta = (long long)1e9 + 7;
int n, a[(int)1e5 + 20], b[(int)1e5 + 20], x, ans;
vector<int> v;
vector<pair<int, int> > out;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < n; ++i) scanf("%d", &x), b[x] = i;
  for (int i = 0; i < n; ++i) a[i] = b[a[i]];
  for (int i = 0; i < n; ++i) {
    if (a[i] == i) continue;
    if (a[i] > i) {
      ans += a[i] - i;
      v.push_back(i);
    } else {
      int u = i;
      for (int j = v.size() - 1; j >= 0; --j) {
        if (v[j] < a[u]) break;
        out.push_back({u + 1, v[j] + 1});
        swap(a[u], a[v[j]]);
        swap(u, v[j]);
        if (a[v[j]] == v[j]) {
          for (int k = j; k + 1 < v.size(); ++k) swap(v[k], v[k + 1]);
          v.pop_back();
        }
      }
    }
  }
  int res = out.size();
  printf("%d\n%d\n", ans, res);
  for (int i = 0; i < out.size(); ++i) {
    printf("%d %d\n", out[i].first, out[i].second);
  }
  return cout << endl, 0;
}
