#include <bits/stdc++.h>
using namespace std;
bool deb = false;
const int N = 100011;
int a[N], b[N], pos[N];
vector<pair<int, int> > s;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n + 1; ++i) scanf("%d", &a[i]);
  for (int i = 1; i < n + 1; ++i) scanf("%d", &b[i]), pos[b[i]] = i;
  int ans = 0;
  for (int i = 1; i < n + 1; ++i) {
    int p = i;
    for (int j = i - 1; j > pos[a[p]] - 1; --j) {
      if (pos[a[j]] >= p) {
        ans += abs(p - j);
        swap(a[p], a[j]);
        s.push_back(make_pair(p, j));
        p = j;
      }
    }
  }
  printf("%d\n", ans);
  printf("%d\n", (int)s.size());
  for (auto i : s) printf("%d ", i.first), printf("%d\n", i.second);
  return 0;
}
