#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int p[n + 1], s[n + 1], invs[n + 1], invp[n + 1], k = 0, cost = 0;
  vector<int> shifti, shiftj;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    invp[p[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
    invs[s[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    int x = s[i];
    for (int j = invp[x] - 1; j >= i; j--) {
      int y = p[j];
      if (invs[y] >= invp[x]) {
        swap(p[invp[x]], p[invp[y]]);
        swap(invp[x], invp[y]);
        cost += abs(invp[x] - invp[y]);
        k++;
        shifti.push_back(invp[x]);
        shiftj.push_back(invp[y]);
      }
    }
  }
  printf("%d\n", cost);
  printf("%d\n", k);
  for (int i = 0; i < k; i++) printf("%d %d\n", shiftj[i], shifti[i]);
  return 0;
}
