VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications.

The latest A/B test suggests that users are reading recommended publications more actively if each category has a different number of publications within daily recommendations. The targeted algorithm can find a single interesting publication of i-th category within t_i seconds. 

What is the minimum total time necessary to add publications to the result of batch algorithm execution, so all categories have a different number of publications? You can't remove publications recommended by the batch algorithm.

Input

The first line of input consists of single integer n — the number of news categories (1 ≤ n ≤ 200 000).

The second line of input consists of n integers a_i — the number of publications of i-th category selected by the batch algorithm (1 ≤ a_i ≤ 10^9).

The third line of input consists of n integers t_i — time it takes for targeted algorithm to find one new publication of category i (1 ≤ t_i ≤ 10^5).

Output

Print one integer — the minimal required time for the targeted algorithm to get rid of categories with the same size.

Examples

Input


5
3 7 9 7 8
5 2 5 7 5


Output


6


Input


5
1 2 3 4 5
1 1 1 1 1


Output


0

Note

In the first example, it is possible to find three publications of the second type, which will take 6 seconds.

In the second example, all news categories contain a different number of publications.
import java.io.*;
import java.util.*;

public class codeforces {
	public static PrintWriter out;
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
	// The next two void functions are shuffle functions on an array.
	// This way, quick sort encounters the worst case scenario with low probability.
	// A reason for doing this is if we don't a primitive data array to an object array.
	// For safety reasons, it would be preferable to use object arrays unless doing so expends a lot of time.
	public static void shuffleLongArray(long[] arr) {
		int n = arr.length;
		Random rnd = new Random();
        for (int i=0; i < n; ++i) {
        	long tmp = arr[i];
        	int randomPos = i + rnd.nextInt(n-i);
        	arr[i] = arr[randomPos];
        	arr[randomPos] = tmp;
        }
	}
	public static void shuffleIntArray(int[] arr) {
		int n = arr.length;
		Random rnd = new Random();
        for (int i=0; i < n; ++i) {
        	int tmp = arr[i];
        	int randomPos = i + rnd.nextInt(n-i);
        	arr[i] = arr[randomPos];
        	arr[randomPos] = tmp;
        }
	}
	public static void main (String[] args) throws IOException {
    	MyScanner sc = new MyScanner();
    	out = new PrintWriter(new BufferedOutputStream(System.out));
    	// Write your solution here.
    	int t = 1;
    	for (int asap=0; asap < t; ++asap) {
    		int n = sc.nextInt();
    		long[][] info = new long[n][2];
    		for (int i=0; i < n; ++i) {
    			info[i][0] = sc.nextLong();
    		}
    		for (int i=0; i < n; ++i) {
    			info[i][1] = sc.nextLong();
    		}
    		if (n==1) {
    			out.println(0); out.close(); return;
    		}
    		Random rnd = new Random();
            for (int i=0; i < n; ++i) {
            	long tmp = info[i][0];
            	long tmp2 = info[i][1];
            	int randomPos = i + rnd.nextInt(n-i);
            	info[i][0] = info[randomPos][0];
            	info[randomPos][0] = tmp;
            	info[i][1] = info[randomPos][1];
            	info[randomPos][1] = tmp2;
            }
            Arrays.sort(info, new Comparator<long[]>() {
    			public int compare (long[] a, long[] b) {
    				if (Long.compare(a[0], b[0]) != 0) return Double.compare(a[0], b[0]);
    				return Long.compare(b[1], a[1]);
    			}
    		});
            /*
            for (int i=0; i < n; ++i) {
            	out.print(info[i][0] + " ");
            }
            out.println();
            for (int i=0; i < n; ++i) {
            	out.print(info[i][1] + " ");
            }
            */
            long price = 0L;
            int batch = 0; long value = info[0][0];
            for (int i=0; i <= n; ++i) { // going back 1 n times is not an issue
            	if (i==0) ++value;
            	else if (i==n) { // new batch at i; check "batch" <= z < i
            		// begin work
            		/*
            		rnd = new Random();
                    for (int k=batch; k < i; ++k) {
                    	long tmp = info[i][0];
                    	long tmp2 = info[i][1];
                    	int randomPos = k + rnd.nextInt(i-batch-k);
                    	info[k][0] = info[randomPos][0];
                    	info[randomPos][0] = tmp;
                    	info[k][1] = info[randomPos][1];
                    	info[randomPos][1] = tmp2;
                    }
                    Arrays.sort(info, batch, i, new Comparator<long[]>() {
            			public int compare (long[] a, long[] b) {
            				if (Long.compare(a[1], b[1]) != 0) return Double.compare(a[1], b[1]);
            				return Long.compare(b[0], a[0]);
            			}
            		});
            		*/
                    // info now sorted by price tag
            		PriorityQueue<long[]> pq = new PriorityQueue<long[]>(new Comparator<long[]>() {
            			public int compare (long[] a, long[] b) {
            				if (a[1] < b[1]) return 1;
            				else if (a[1] > b[1]) return -1;
            				else if (a[0] > b[0]) return -1;
            				else if (a[0] < b[0]) return 1;
            				else return 0;
            			}
            		});
            		int counter = i-batch;
            		long stretch = (long) counter;
                    for (long u = value-stretch; u <= value-1; ++u) {
                    	while (counter > 0 && info[i-counter][0] <= u) {
                    		pq.add(info[i-counter]);
                    		--counter;
                    	}
                    	long[] seen = pq.peek();
                    	pq.remove();
                    	price += (u-seen[0])*seen[1];
                    	// out.println(price);
                    }
            		// end work
            		batch = i;
            	}
            	else if (info[i][0] >= value) { // new batch at i; check "batch" <= z < i
            		// begin work
            		/*
            		rnd = new Random();
                    for (int k=batch; k < i; ++k) {
                    	long tmp = info[i][0];
                    	long tmp2 = info[i][1];
                    	int randomPos = k + rnd.nextInt(i-batch-k);
                    	info[k][0] = info[randomPos][0];
                    	info[randomPos][0] = tmp;
                    	info[k][1] = info[randomPos][1];
                    	info[randomPos][1] = tmp2;
                    }
                    Arrays.sort(info, batch, i, new Comparator<long[]>() {
            			public int compare (long[] a, long[] b) {
            				if (Long.compare(a[1], b[1]) != 0) return Double.compare(a[1], b[1]);
            				return Long.compare(b[0], a[0]);
            			}
            		});
            		*/
                    // info now sorted by price tag
            		PriorityQueue<long[]> pq = new PriorityQueue<long[]>(new Comparator<long[]>() {
            			public int compare (long[] a, long[] b) {
            				if (a[1] < b[1]) return 1;
            				else if (a[1] > b[1]) return -1;
            				else if (a[0] > b[0]) return -1;
            				else if (a[0] < b[0]) return 1;
            				else return 0;
            			}
            		});
            		int counter = i-batch;
            		long stretch = (long) counter;
                    for (long u = value-stretch; u <= value-1; ++u) {
                    	while (counter > 0 && info[i-counter][0] <= u) {
                    		pq.add(info[i-counter]);
                    		--counter;
                    	}
                    	long[] seen = pq.peek();
                    	pq.remove();
                    	price += (u-seen[0])*seen[1];
                    	// out.println(price);
                    }
            		// end work
            		batch = i;
            		value = info[i][0]+1;
            	}
            	else ++value;
            	// out.println("Value = " + value);
            }
            out.println(price);
    	}
    	out.close();
	}
}