#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 5e5 + 10;
int arr[N], brr[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    brr[a] = i;
  }
  int ans = 0;
  vector<pair<int, int>> res;
  while (1) {
    int save = -1;
    for (int i = 0; i < n; i++) {
      if (brr[arr[i]] < i) {
        save = i;
        break;
      }
    }
    if (save == -1) break;
    int pos = save;
    int dest = brr[arr[save]];
    for (int i = save - 1; i >= dest; i--) {
      if (brr[arr[i]] > i) {
        swap(arr[pos], arr[i]);
        res.push_back({pos + 1, i + 1});
        ans += pos - i;
        pos = i;
      }
    }
  }
  cout << ans << "\n";
  cout << res.size() << "\n";
  for (auto it : res) cout << it.first << " " << it.second << "\n";
  return 0;
}
