#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, p[N], s[N];
vector<pair<int, int> > ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  for (int i = n; i >= 1; i--) {
    for (int j = i; j <= n; j++) {
      if (p[i] == s[j]) {
        int u = i;
        for (int k = i + 1; k <= j; k++) {
          if (p[k] == s[k]) continue;
          ans.push_back(make_pair(u, k));
          swap(p[u], p[k]);
          u = k;
        }
        break;
      }
    }
  }
  long long sum = 0;
  for (int i = 0; i < (int)ans.size(); i++)
    sum += abs(ans[i].first - ans[i].second);
  printf("%lld\n", sum);
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
