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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class DimaAndLiza {

	public static void main(String[] args) {
		InputReader ir = new InputReader(System.in);
		int n = ir.nextInt();
		int p[] = new int [n];
		int s[] = new int [n];
		for (int i = 0; i < n; ++i) {
			p[i] = ir.nextInt();
		}
		for (int i = 0; i < n; ++i) {
			s[i] = ir.nextInt();
		}
		
		int indexInS[] = new int[n+1];
		int indexInP[] = new int[n+1];
		for (int i = 0; i < n; ++i) {
			indexInS[s[i]] = i;
			indexInP[p[i]] = i;
		}
		
		int answer = 0;
		/*for (int i = 1; i <= n; ++i) {
			answer += Math.abs(indexInP[i] - indexInS[i]);
		}*/
		
		LinkedList<Swap> operations = new LinkedList<>();
		for (int k = n-1; k >= 0; --k) {
			while (indexInP[s[k]] != k) {
				int i = indexInP[s[k]];
				int j;
				for (j = i+1; indexInS[p[j]] > i; ++j);
				
				p[i] = p[j];
				p[j] = s[k];
				
				indexInP[p[i]] = i;
				indexInP[p[j]] = j;
				
				operations.add(new Swap(i+1, j+1));
				answer += j - i;
			}
		}
		OutputWriter ow = new OutputWriter(System.out);
		ow.printLine(answer);
		ow.printLine(operations.size());
		for (Swap operation : operations) {
			ow.printLine(operation.i, operation.j);
		}
		ow.close();
	}

	
	private static class Swap {
		private int i, j;
		private Swap(int i, int j) {
			this.i = i;
			this.j = j;
		}
	}
}


class InputReader {
    private InputStream stream;
    private byte[] buffer = new byte[10000];
    private int cur;
    private int count;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public static boolean isSpace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int read() {
        if (count == -1) {
            throw new InputMismatchException();
        }
        try {
            if (cur >= count) {
                cur = 0;
                count = stream.read(buffer);
                if (count <= 0)
                    return -1;
            }
        } catch (IOException e) {
            throw new InputMismatchException();
        }
        return buffer[cur++];
    }

    public int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

    public long nextLong() {
        int sgn = 1;
        int c = readSkipSpace();
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res = res * 10 + c - '0';
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }
    
    public int nextInt(){return (int)nextLong();}
    
    public String nextString() {
    	String result = "";
    	int c = readSkipSpace();
    	do {
    		result += (char) c;
    		c = read();
    	} while(!isSpace(c));
    	return result;
    }

}


class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) {
                writer.print(' ');
            }
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

}

class Pair <T1, T2> implements Comparable<Pair < T1, T2>> {
	public T1 first;
	public T2 second;
	public Pair(T1 first, T2 second) {
		this.first = first;
		this.second = second;
	}
	@SuppressWarnings("unchecked")
	@Override
	public int compareTo(Pair<T1, T2> arg0) {
		int firstCompare = ((Comparable<T1>)first).compareTo(arg0.first);
		return firstCompare == 0 ? ((Comparable<T2>)second).compareTo(arg0.second) : firstCompare;
	}
	
}

class Algorithm {
	@SuppressWarnings({ "rawtypes", "unchecked" })
	static Comparable maxElement(Comparable[] array) {
		Comparable result = array[0];
		for (Comparable element : array) {
			if (result.compareTo(element) < 0) {
				result = element;
			}
		}
		return result;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static int lowerBoundIndex(Comparable[] array, int first, int last, Comparable value) {
		int count = last-first;
		while (count>0) { 
			int step = count / 2;
			int index = first+step;
			if (array[index].compareTo(value) < 0) {
				first = ++index;
				count -= step+1;
			} else {
				count = step;
			}
		}
		return first;
	}
	
	@SuppressWarnings("rawtypes")
	public static int lowerBoundIndex(Comparable[] array, Comparable value) {
		return lowerBoundIndex(array, 0, array.length, value);
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static int upperBoundIndex(Comparable[] array, int first, int last, Comparable value) {
		int count = last-first;
		while (count>0) { 
			int step = count / 2;
			int index = first+step;
			if (value.compareTo(array[index]) >= 0) {
				first = ++index;
				count -= step+1;
			} else {
				count = step;
			}
		}
		return first;
	}
	
	@SuppressWarnings("rawtypes")
	public static int upperBoundIndex(Comparable[] array, Comparable value) {
		return upperBoundIndex(array, 0, array.length, value);
	}

	
}