#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T& x, L y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T& x, L y) {
  return x > y ? (x = y, 1) : 0;
}
const int maxn = 2e3 + 17;
int n, p[maxn], prv[maxn], s[maxn];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 0, x; i < n; i++) cin >> x, s[x - 1] = i;
  for (int i = 0, x; i < n; i++) cin >> x, p[s[x - 1]] = i;
  int ans = 0;
  vector<pair<int, int> > res;
  for (int i = 0; i < n; i++) {
    int pos = find(p, p + n, i) - p;
    for (int j = 0; j < n; j++)
      if (j && p[j] < p[prv[j - 1]])
        prv[j] = prv[j - 1];
      else
        prv[j] = j;
    while (pos != i) {
      int idx = prv[pos - 1];
      ans += pos - idx;
      swap(p[pos], p[idx]);
      res.push_back({pos + 1, idx + 1});
      pos = idx;
    }
  }
  cout << ans << '\n' << res.size() << '\n';
  for (auto x : res) cout << x.first << ' ' << x.second << '\n';
  return 0;
}
