#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
set<pair<int, int> > L, R;
vector<pair<int, int> > vrt;
int P[N], second[N], IND[N], A[N], n, rt;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &P[i]);
  for (int i = 0; i < n; i++) {
    scanf("%d", &second[i]);
    IND[second[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    A[i] = IND[P[i]];
    rt += abs(i - A[i]);
  }
  for (int i = 0; i < n; i++) {
    if (A[i] < i) R.insert({i, A[i]});
    if (A[i] > i) L.insert({i, A[i]});
  }
  while (L.size()) {
    auto itl = L.end();
    itl--;
    auto itr = R.lower_bound(*itl);
    L.erase(itl);
    R.erase(itr);
    pair<int, int> pl = *itl, pr = *itr;
    swap(pl.first, pr.first);
    vrt.push_back({itl->first, itr->first});
    if (pl.first ^ pl.second) L.insert(pl);
    if (pr.first ^ pr.second) R.insert(pr);
  }
  printf("%d\n%d\n", rt >>= 1, (int)vrt.size());
  for (pair<int, int> x : vrt) printf("%d %d\n", x.first + 1, x.second + 1);
}
