#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 10;
int n, tmp, ans, p[N], q[N], pos[N];
vector<pair<int, int> > vec;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int i, j;
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> p[i];
  for (i = 1; i <= n; ++i) cin >> q[i];
  for (i = 1; i <= n; ++i) pos[p[i]] = i;
  for (i = 1; i <= n; ++i) p[pos[q[i]]] = i;
  for (i = 1; i <= n; ++i) pos[p[i]] = i;
  for (i = n; i >= 1; --i) {
    while (pos[i] != i) {
      for (j = pos[i] + 1; j <= i; ++j) {
        if (p[j] <= pos[i]) {
          tmp = pos[i];
          ans += j - pos[i];
          vec.push_back({pos[i], j});
          swap(pos[i], pos[p[j]]);
          swap(p[tmp], p[j]);
          break;
        }
      }
    }
  }
  cout << ans << '\n';
  cout << vec.size() << '\n';
  for (auto x : vec) cout << x.first << ' ' << x.second << '\n';
  return 0;
}
