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;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
void usaco(string filename) {
  freopen((filename + ".in").c_str(), "r", stdin);
  freopen((filename + ".out").c_str(), "w", stdout);
}
const long double pi = 3.14159265358979323846;
const long long mod = 1000000007;
long long n, m, q, k, l, r, x, y, z;
const long long template_array_size = 1e6 + 15258;
long long a[template_array_size];
long long b[template_array_size];
long long c[template_array_size];
string second, t;
void solve(int tc = 0) {
  cin >> n;
  vector<pair<long long, long long>> ops;
  for (long long i = 0; i < n; i++) cin >> b[i];
  for (long long i = 0; i < n; i++) cin >> a[i], c[a[i]] = i;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long loc = -1;
    for (long long j = i; j < n; j++) {
      if (b[j] == a[i]) loc = j;
    }
    assert(loc != -1);
    for (long long j = loc - 1; j > i; j--) {
      if (loc <= c[b[j]]) {
        swap(b[j], b[loc]);
        ops.push_back({j, loc});
        ans += abs(loc - j);
        loc = j;
      }
    }
    if (loc > i) {
      swap(b[loc], b[i]);
      ops.push_back({loc, i});
      ans += abs(loc - i);
    }
    assert(a[i] == b[i]);
  }
  cout << ans << '\n' << ops.size() << '\n';
  for (pair<long long, long long> x : ops)
    cout << x.first + 1 << " " << x.second + 1 << '\n';
}
int main() {
  { ios_base::sync_with_stdio(false); }
  { cin.tie(NULL); }
  cout << setprecision(15) << fixed;
  int tc = 1;
  for (int t = 0; t < tc; t++) solve(t);
}