#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    b[x - 1] = i;
  }
  for (int i = 0; i < n; ++i) a[i] = b[a[i] - 1];
  int cnt = 0;
  vector<pair<int, int> > ans;
  for (int k = n - 1; k >= 0; --k) {
    for (int i = 0; i < n; ++i) {
      if (a[i] == k) {
        int cur = i;
        while (a[cur] != cur) {
          for (int j = cur + 1; j < n; ++j) {
            if (a[j] <= cur) {
              cnt += j - cur;
              ans.push_back({j + 1, cur + 1});
              swap(a[j], a[cur]);
              cur = j;
              break;
            }
          }
        }
        break;
      }
    }
  }
  cout << cnt << '\n';
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); ++i)
    cout << ans[i].first << " " << ans[i].second << '\n';
}
