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;
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;
}