#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e3 + 5;
int p[maxn], s[maxn], dest[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, i, j;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> p[i];
  for (i = 1; i <= n; i++) {
    cin >> s[i];
    dest[s[i]] = i;
  }
  int ans = 0;
  vector<pair<int, int> > value;
  for (i = n; i > 0; i--) {
    int pos = i;
    for (j = i + 1; j <= dest[p[pos]]; j++) {
      if (dest[p[j]] <= pos) {
        value.push_back({j, pos});
        swap(p[j], p[pos]);
        ans += j - pos;
        pos = j;
      }
    }
  }
  cout << ans << "\n";
  cout << int(value.size()) << "\n";
  for (auto it : value) cout << it.first << " " << it.second << "\n";
  return 0;
}
