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.
import java.io.*;
import java.util.*;

/**
 * Created by sbabkin on 9/14/2015.
 */
public class SolverE {

    public static void main(String[] args) throws IOException {
        new SolverE().Run();
    }

    BufferedReader br;
    PrintWriter pw;
    StringTokenizer stok;

    private String nextToken() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            stok = new StringTokenizer(br.readLine());
        }
        return stok.nextToken();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private void Run() throws IOException {
//        br = new BufferedReader(new FileReader("input.txt"));
//        pw = new PrintWriter("output.txt");
        br=new BufferedReader(new InputStreamReader(System.in));
        pw=new PrintWriter(new OutputStreamWriter(System.out));

        solve();
        pw.flush();
        pw.close();
    }

    private void solve() throws IOException {
        int n = nextInt();
        int resMoney = 0;
        List<Integer> p1 = new ArrayList<Integer>(n*n);
        List<Integer> p2 = new ArrayList<Integer>(n*n);
        int[] mas = new int[n];
        for (int i = 0; i < n; i++) {
            mas[i] = nextInt() - 1;
        }
        int[] place = new int[n];
        for (int i = 0; i < n; i++) {
            place[nextInt() - 1] = i;
        }
        Deque<Integer> open = new ArrayDeque<Integer>();
        Deque<Integer> rest = new ArrayDeque<Integer>();
        int[] next = new int[n];
        int last = -1;
        for (int i = n - 1; i >= 0; i--) {
            next[i] = last;
            if (place[mas[i]] != i) {
                last = i;
            }
        }
        int i;
        for (i = 0; i < n && place[mas[i]] >= i; i++) {
            if (place[mas[i]] > i) {
                open.push(i);
            }
        }
        for (int j = n - 1; j >= i; j--) {
            if (place[mas[i]] != i) {
                rest.push(j);
            }
        }
        while (!open.isEmpty()) {
            int curOpen = open.pop();
            int curClose = rest.pop();
            resMoney += Math.abs(curOpen - curClose);
            p1.add(curOpen + 1);
            p2.add(curClose + 1);
            int buf = mas[curOpen];
            mas[curOpen] = mas[curClose];
            mas[curClose] = buf;
            rest.push(curClose);
            rest.push(curOpen);
//            if (place[mas[curOpen]] < curOpen) {
//                if (place[mas[curClose]] != curClose) {
//                    rest.push(curClose);
//                }
//                rest.push(curOpen);
//            } else {
//                if (place[mas[curClose]] > curClose) {
//                    open.push(curClose);
//                } else if (place[mas[curClose]] < curClose) {
//                    rest.push(curClose);
//                }
//            }
            boolean ok=true;
            while (ok && !rest.isEmpty()) {
                int val = rest.pop();
                if (place[mas[val]]<val) {
                    ok=false;
                    rest.push(val);
                } else if (place[mas[val]]>val) {
                    open.push(val);
                }
            }
//            while (!rest.isEmpty() && place[mas[rest.peek()]]>=rest.peek()){
//                int val = rest.pop();
//                if (place[mas[val]]>val) {
//                    open.push(val);
//                }
//            }
        }
        pw.println(resMoney);
        pw.println(p1.size());
        for (i = 0; i < p1.size(); i++) {
            pw.println(p1.get(i) + " " + p2.get(i));
        }
    }

}
