#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cout << setprecision(10);
  int n;
  cin >> n;
  int b[n + 1];
  int p[n];
  int s[n];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    b[s[i]] = i;
  }
  int ans = 0;
  vector<pair<int, int>> out;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int x = b[p[j]];
      if (x > j) {
        for (int k = x; k > j; k--) {
          if (b[p[k]] <= j) {
            out.push_back({j, k});
            ans += abs(j - k);
            int t = p[k];
            p[k] = p[j];
            p[j] = t;
            break;
          }
        }
      } else if (x < j) {
        for (int k = x; k < j; k++) {
          if (b[p[k]] >= j) {
            out.push_back({j, k});
            ans += abs(j - k);
            int t = p[k];
            p[k] = p[j];
            p[j] = t;
            break;
          }
        }
      }
    }
  }
  cout << endl;
  cout << ans << endl;
  cout << out.size() << endl;
  for (int i = 0; i < out.size(); i++) {
    cout << out[i].first + 1 << " " << out[i].second + 1 << endl;
  }
}
