#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 30;
int n, ar[maxn], br[maxn], des[maxn], ans, cnt;
pair<int, int> vec[maxn * maxn];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ar[i];
  for (int i = 1; i <= n; i++) {
    cin >> br[i];
    des[br[i]] = i;
  }
  for (int i = 1, l; i <= n; i++) {
    l = i;
    if (des[ar[i]] < i) {
      ans += i - des[ar[i]];
      for (int j = i - 1; j >= des[ar[l]] && j > 0; j--)
        if (j < des[ar[j]]) vec[cnt++] = {l, j}, swap(ar[l], ar[j]), l = j;
    }
  }
  cout << ans << '\n';
  cout << cnt << '\n';
  for (auto x = 0; x < cnt; x++)
    cout << vec[x].first << ' ' << vec[x].second << '\n';
}
