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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Round623D {

	public static class node{
		long max;
		long sum;
		int max_id;
		node(long max, long sum, int max_id){
			this.max = max;
			this.max_id = max_id;
			this.sum = sum;
		}
	}
	public static node merge(node A, node B) {
		int max_id = -1;
		long max = Long.max(A.max, B.max);
		if(A.max == max) {
			max_id = A.max_id;
		}else {
			max_id = B.max_id;
		}
		long sum = 0;
		if(A.sum != Long.MIN_VALUE) {
			sum+=A.sum;
		}
		if(B.sum != Long.MIN_VALUE) {
			sum+=B.sum;
		}
		return new node(max, sum, max_id);
	}
	
	public static void Build(node[] tree, long[] arr, int start, int end, int index) {
		if(start == end) {
			tree[index] = new node(arr[start], arr[start], start);
			return;
		}
		int mid = (start + end)>>1;
		Build(tree, arr, start, mid, index<<1);
		Build(tree, arr, mid+1, end, index<<1|1);
		tree[index] = merge(tree[index<<1], tree[index<<1|1]);
	}
	
	public static void Update(node[] tree, int start, int end, int index, int idx, long val) {
		if(idx < start || idx > end) {
			return;
		}
		if(start == end) {
			tree[index] = new node(val, val, idx);
			return;
		}
		int mid = (start + end)>>1;
		Update(tree, start, mid, index<<1, idx, val);
		Update(tree, mid+1, end, index<<1|1, idx, val);
		tree[index] = merge(tree[index<<1], tree[index<<1|1]);
	}
	
	public static class Pair implements Comparable<Pair>{
		long pub;
		long time;
		Pair(long pub, long time){
			this.pub = pub;
			this.time = time;
		}
		public int compareTo(Pair x) {
			if(this.pub == x.pub)return Long.compare(this.time, x.time);
			return Long.compare(this.pub, x.pub);
		}
	}
	
	public static void solve() {
		int n = s.nextInt();
		node[] tree = new node[4 * n + 1];
		long[] temp1 = new long[n];
		for(int i = 0; i < n; i++) {
			temp1[i] = s.nextLong();
		}
		Pair[] pu = new Pair[n];
		for(int i = 0; i < n; i++) {
			long x = s.nextLong();
			pu[i] = new Pair(temp1[i], x);
		}
		Arrays.sort(pu);
		Arrays.fill(tree, new node(Long.MIN_VALUE, Long.MIN_VALUE, Integer.MIN_VALUE));
		Build(tree, new long[n], 0, n-1, 1);
		int pos = 0;
		long time = 0;
		for(int i = 0; i < n; i++) {
			time += tree[1].sum;
			long cur = pu[i].pub;
			int j = i + 1;
			Update(tree, 0, n-1, 1, pos, pu[i].time);
			pos++;
			while(j < n && pu[i].pub == pu[j].pub) {
				Update(tree, 0, n-1, 1, pos, pu[j].time);
				j++;
				pos++;
			}
			i = j - 1;
			int idx = tree[1].max_id;
			Update(tree, 0, n-1, 1, idx, Long.MIN_VALUE);
			for(long k = cur+1; (i+1 < n ? k < pu[i+1].pub : k < Long.MAX_VALUE); k++) {
				if(tree[1].max == 0 || tree[1].max == Long.MIN_VALUE) {
					break;
				}
				time+=tree[1].sum;
				idx = tree[1].max_id;
				Update(tree, 0, n-1, 1, idx, Long.MIN_VALUE);
			}
		}
		out.println(time);
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	
}
