#include <bits/stdc++.h>
using namespace std;
struct Seg {
  int l, r, v[2];
};
Seg seg[10010];
int p[2010], q[2010], mp[2010], a[2010];
multiset<pair<int, int>> ss;
void up(int id) {
  seg[id].v[0] = p[seg[id * 2].v[0]] > p[seg[id * 2 + 1].v[0]]
                     ? seg[id * 2].v[0]
                     : seg[id * 2 + 1].v[0];
  seg[id].v[1] = p[seg[id * 2].v[1]] < p[seg[id * 2 + 1].v[1]]
                     ? seg[id * 2].v[1]
                     : seg[id * 2 + 1].v[1];
}
void build(int id, int L, int R) {
  seg[id].l = L;
  seg[id].r = R;
  if (L == R) {
    seg[id].v[0] = seg[id].v[1] = L;
  } else {
    int mid = (L + R) / 2;
    build(id * 2, L, mid);
    build(id * 2 + 1, mid + 1, R);
    up(id);
  }
}
void update(int id, int pos) {
  if (seg[id].l == seg[id].r) {
    return;
  }
  int mid = (seg[id].l + seg[id].r) / 2;
  if (pos <= mid) {
    update(id * 2, pos);
  } else {
    update(id * 2 + 1, pos);
  }
  up(id);
}
int query(int id, int l, int r, int x) {
  if (seg[id].l >= l && seg[id].r <= r) {
    return seg[id].v[x];
  }
  int mid = (seg[id].l + seg[id].r) / 2;
  if (r <= mid) {
    return query(id * 2, l, r, x);
  } else if (l > mid) {
    return query(id * 2 + 1, l, r, x);
  } else {
    int id1 = query(id * 2, l, r, x);
    int id2 = query(id * 2 + 1, l, r, x);
    if (x == 0) {
      return p[id1] > p[id2] ? id1 : id2;
    } else {
      return p[id1] < p[id2] ? id1 : id2;
    }
  }
}
pair<int, int> ope[2000010];
int opecnt = 0;
void exchange(int x, int y, int &sum) {
  ope[opecnt++] = make_pair(x, y);
  int tmp = p[x];
  ss.erase(ss.find(make_pair(abs(a[x]), a[x] > 0 ? x : -x)));
  if (a[x] > 0) {
    sum -= a[x];
  }
  p[x] = p[y];
  a[x] = p[x] - x;
  if (a[x] > 0) {
    sum += a[x];
  }
  ss.insert(make_pair(abs(a[x]), a[x] > 0 ? x : -x));
  update(1, x);
  ss.erase(ss.find(make_pair(abs(a[y]), a[y] > 0 ? y : -y)));
  if (a[y] > 0) {
    sum -= a[y];
  }
  p[y] = tmp;
  a[y] = p[y] - y;
  if (a[y] > 0) {
    sum += a[y];
  }
  ss.insert(make_pair(abs(a[y]), a[y] > 0 ? y : -y));
  update(1, y);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &q[i]);
    mp[q[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    p[i] = mp[p[i]];
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i] > i) {
      sum += p[i] - i;
    }
    a[i] = p[i] - i;
    ss.insert(make_pair(abs(a[i]), (a[i] > 0 ? i : -i)));
  }
  build(1, 1, n);
  printf("%d\n", sum);
  while (sum > 0) {
    auto x = *ss.rbegin();
    int pos = abs(x.second);
    if (a[pos] > 0) {
      int id = query(1, pos + 1, p[pos], 1);
      exchange(pos, id, sum);
    } else {
      int id = query(1, p[pos], pos - 1, 0);
      exchange(pos, id, sum);
    }
  }
  printf("%d\n", opecnt);
  for_each(ope, ope + opecnt,
           [](pair<int, int> &x) { printf("%d %d\n", x.first, x.second); });
  return 0;
}
