#include <bits/stdc++.h>
using namespace std;
int totCost = 0;
int P[2003], target[2003], posInTarget[2003], n;
int best[2003], ansLen, ans1[2003 * 2003 / 2], ans2[2003 * 2003 / 2];
int getBest(int i, int j) {
  if (P[i] > P[j]) return i;
  return j;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> P[i];
  for (int i = 1; i <= n; ++i) {
    cin >> target[i];
    posInTarget[target[i]] = i;
  }
  for (int i = 1; i <= n; ++i) P[i] = posInTarget[P[i]];
  for (int i = 1; i <= n; ++i) {
    int posi = i, newPosi;
    while (P[posi] != i) posi++;
    best[i] = i;
    for (int j = i + 1; j < posi; ++j) best[j] = getBest(j, best[j - 1]);
    while (posi > i) {
      newPosi = best[posi - 1];
      ans1[ansLen] = newPosi;
      ans2[ansLen++] = posi;
      totCost += abs(posi - newPosi);
      swap(P[posi], P[newPosi]);
      posi = newPosi;
    }
  }
  cout << totCost << "\n" << ansLen << '\n';
  for (int i = 0; i < ansLen; ++i) cout << ans1[i] << ' ' << ans2[i] << '\n';
  return 0;
}
