#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> from(n), to(n), arr(n), rev_need(n);
  int x;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    from[x - 1] = i;
    arr[i] = x - 1;
  }
  for (int i = 0; i < n; ++i) {
    cin >> x;
    to[x - 1] = i;
    rev_need[i] = x - 1;
  }
  reverse(rev_need.begin(), rev_need.end());
  int ans = 0;
  vector<pair<int, int>> ans_swap;
  for (int i : rev_need) {
    int pos = from[i];
    for (int j = pos + 1; j <= to[i]; ++j) {
      if (to[arr[j]] <= pos) {
        from[arr[j]] = pos;
        swap(arr[pos], arr[j]);
        ans += j - pos;
        ans_swap.emplace_back(pos + 1, j + 1);
        pos = j;
      }
    }
  }
  cout << ans << '\n';
  cout << ans_swap.size() << '\n';
  for (auto [i, j] : ans_swap) cout << i << ' ' << j << '\n';
  return 0;
}
