#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, a[100100], b[100100];
int p[100100], pos[100100];
long long ans = 0;
vector<pair<int, int> > res;
int t[8 * 1000], posa[100100], posb[100100];
int tm[100100];
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = p[tl];
  } else {
    int mid = (tl + tr) >> 1;
    build(2 * v, tl, mid);
    build(2 * v + 1, mid + 1, tr);
    t[v] = max(t[2 * v], t[2 * v + 1]);
  }
}
int get(int v, int tl, int tr, int l, int r) {
  if (r < tl || l > tr) return -inf;
  if (l <= tl && tr <= r) return t[v];
  int mid = (tl + tr) >> 1;
  return max(get(2 * v, tl, mid, l, r), get(2 * v + 1, mid + 1, tr, l, r));
}
void update(int v, int tl, int tr, int pos, int val) {
  if (tl == tr) {
    t[v] = val;
  } else {
    int mid = (tl + tr) >> 1;
    if (pos <= mid)
      update(2 * v, tl, mid, pos, val);
    else
      update(2 * v + 1, mid + 1, tr, pos, val);
    t[v] = max(t[2 * v], t[2 * v + 1]);
  }
}
int getlast(int v, int tl, int tr, int r, int val) {
  if (tl == tr) return tl;
  int mid = (tl + tr) >> 1;
  int L = get(2 * v, tl, mid, 0, r);
  int R = get(2 * v + 1, mid + 1, tr, 0, r);
  if (R >= val)
    return getlast(2 * v + 1, mid + 1, tr, r, val);
  else
    return getlast(2 * v, tl, mid, r, val);
}
void update(int ind) { update(1, 0, n - 1, ind, p[ind]); }
void sw(int x, int y) {
  ans += abs(x - y);
  res.push_back(make_pair(x, y));
  swap(p[x], p[y]);
  pos[p[x]] = x;
  pos[p[y]] = y;
  update(x);
  update(y);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    a[i]--;
    posa[a[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", b + i);
    b[i]--;
    posb[b[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    int x = b[i];
    int ind = posa[x];
    p[ind] = i;
  }
  for (int i = 0; i < n; i++) pos[p[i]] = i;
  build(1, 0, n - 1);
  for (int i = 0; i < n; i++) {
    int j = pos[i];
    while (j > i) {
      int ind = getlast(1, 0, n - 1, j, j);
      assert(ind != j);
      assert(j > ind && ind >= i);
      sw(ind, j);
      j = ind;
    }
  }
  cout << ans << endl;
  printf("%d\n", (int)res.size());
  for (__typeof(res.begin()) it = res.begin(); it != res.end(); it++) {
    printf("%d %d\n", (*it).first + 1, (*it).second + 1);
  }
  return 0;
}
