#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e9;
const int maxn = 2000 + 100;
int p[maxn];
int a[maxn];
vector<pair<int, int> > u;
int n;
int find() {
  for (int i = 0; i < n; i++) {
    if (a[i] < i) return i;
  }
  return -1;
}
int find2(int x) {
  for (int i = x - 1; true; i--) {
    if (a[i] > i) return i;
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    p[t - 1] = i;
  }
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    t--;
    a[p[t]] = i;
  }
  bool h = 0;
  int x;
  int ans = 0;
  while (true) {
    if (!h) {
      x = find();
      if (x == -1) break;
      h = 1;
    }
    int y = find2(x);
    ans += (x - y);
    swap(a[x], a[y]);
    u.push_back({x + 1, y + 1});
    if (a[y] < y)
      x = y;
    else
      h = 0;
  }
  cout << ans << endl;
  cout << u.size() << endl;
  for (int i = 0; i < u.size(); i++)
    cout << u[i].first << ' ' << u[i].second << '\n';
}
