#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2017;
int A[MAXN], B[MAXN], P[MAXN], n, ans;
vector<pair<int, int>> V;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", A + i);
  for (int i = 1; i <= n; ++i) scanf("%d", B + i);
  for (int i = 1; i <= n; ++i) P[B[i]] = i;
  for (int i = n; i >= 1; --i) {
    int pos = i;
    for (int j = i + 1; j <= P[A[pos]]; ++j) {
      if (P[A[j]] <= pos) {
        ans += abs(j - pos);
        V.push_back({pos, j});
        swap(A[pos], A[j]);
        pos = j;
      }
    }
  }
  printf("%d\n", ans);
  printf("%d\n", V.size());
  for (int i = 0; i < V.size(); ++i) printf("%d %d\n", V[i].first, V[i].second);
}
