Problem: Anton loves transforming one permutation into another one by swapping elements for money, and Ira doesn't like paying for stupid games. Help them obtain the required permutation by paying as little money as possible.

More formally, we have two permutations, p and s of numbers from 1 to n. We can swap pi and pj, by paying |i - j| coins for it. Find and print the smallest number of coins required to obtain permutation s from permutation p. Also print the sequence of swap operations at which we obtain a solution. 

Input

The first line contains a single number n (1 ≤ n ≤ 2000) — the length of the permutations.

The second line contains a sequence of n numbers from 1 to n — permutation p. Each number from 1 to n occurs exactly once in this line.

The third line contains a sequence of n numbers from 1 to n — permutation s. Each number from 1 to n occurs once in this line.

Output

In the first line print the minimum number of coins that you need to spend to transform permutation p into permutation s.

In the second line print number k (0 ≤ k ≤ 2·106) — the number of operations needed to get the solution.

In the next k lines print the operations. Each line must contain two numbers i and j (1 ≤ i, j ≤ n, i ≠ j), which means that you need to swap pi and pj.

It is guaranteed that the solution exists.

Examples

Input

4
4 2 1 3
3 2 4 1


Output

3
2
4 3
3 1

Note

In the first sample test we swap numbers on positions 3 and 4 and permutation p becomes 4 2 3 1. We pay |3 - 4| = 1 coins for that. On second turn we swap numbers on positions 1 and 3 and get permutation 3241 equal to s. We pay |3 - 1| = 2 coins for that. In total we pay three coins.

Solution (in CPP):

Solution:
#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;
}