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 tr2 {
	static PrintWriter out;
	static StringBuilder sb;
	static long inf = (long) 1e10;
	static ArrayList<Integer> primes;
	static ArrayList<Integer>[] ad;
	static int[] si;
	static long mod = (long) 998244353;
	static long num = (long) 1e9 + 7;
	static long[][] memo;
	static int n;
	static long k;
	static double m;
	static int[] a;
	static char[] s;
	static TreeSet<Integer> pr;
	static ArrayList<Integer> factors, times;
	static TreeSet<Integer> taken, ans;
	static TreeMap<pair1, Integer> edge;
	static boolean[] vis;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
        PriorityQueue<pair1> pq=new PriorityQueue<>();
        n=sc.nextInt();
        int []f=new int [n];
        int []l=new int [n];
        pair []a=new pair  [n];
        for(int i=0;i<n;i++)
        	f[i]=sc.nextInt();
        for(int i=0;i<n;i++) {
        	l[i]=sc.nextInt();
        	a[i]=new pair(f[i], l[i]);
        }
        Arrays.sort(a);
        long ans=0;
        long sum=0;
        int las=-1;
        for(int i=0;i<n;) {
        	int bit=0;
        	while(i<n-1 && a[i].x==a[i+1].x) {
        		bit=1;
        		pq.add(new pair1(a[i].x, a[i].y));
        		sum+=(long)a[i].y;
        		i++;
        	}
        	if(bit==1) {
        		pq.add(new pair1(a[i].x, a[i].y));
        		sum+=(long)a[i].y;
        	}
        	las=a[i].x;
        	i++;
        //	System.out.println(pq);
        	for(int j=las;!pq.isEmpty();j++) {
        	       	while(i<n && j==a[i].x) {
        	       		pq.add(new pair1(a[i].x, a[i].y));
        	       		sum+=(long)a[i].y;
        	       		i++;
        	       	}
        	       	pair1 cur=pq.remove();
        	       	sum-=cur.y;
        	       	ans+=sum;
        	  //     	System.out.println(j+" "+pq);
        	}
        }
        out.print(ans);
		out.flush();
	}
	public static class pair implements Comparable<pair> {
		int x;
		int y;

		pair(int a, int b) {
			x = a;
			y = b;
			// id = g;
		}

		public String toString() {
			return x + " " + y;
		}

		@Override
		public int compareTo(pair o) {
			return x - o.x;
		}
	}
	public static class pair1 implements Comparable<pair1> {
		int x;
		int y;

		pair1(int a, int b) {
			x = a;
			y = b;
			// id = g;
		}

		public String toString() {
			return x + " " + y;
		}

		@Override
		public int compareTo(pair1 o) {
			return o.y - y;
		}
	}

	static long inver(long x) {
		long a = x;
		long e = (mod - 2);
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1) {
				res = ((1l * res * a) % mod);
			}
			a = (int) ((1l * a * a) % mod);
			e >>= 1;
		}
		return res % mod;
	}

	static class eq implements Comparable<eq> {
		int x;
		int y;
		long z;

		eq(int x, int y, long z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		@Override
		public int compareTo(eq o) {
			if (x == o.x)
				if (o.y == y)
					return Long.compare(z, o.z);
				else
					return y - o.y;
			else
				return x - o.x;
		}
	}

	static void seive() {
		si = new int[1000001];
		primes = new ArrayList<>();
		int N = 1000001;
		si[1] = 1;
		for (int i = 2; i < N; i++) {
			if (si[i] == 0) {
				si[i] = i;
				primes.add(i);
				pr.add(i);
			}
			for (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)
				si[primes.get(j) * i] = primes.get(j);

		}
	}

	static long fac(int n) {
		if (n == 0)
			return 1;
		if (n == 1)
			return 1;
		long ans = 1;
		for (int i = 1; i <= n; i++)
			ans = (i % mod * ans % mod) % mod;
		return ans % mod;
	}

	static int gcd(int a, int b) {

		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	

	static class unionfind {
		int[] p;
		int[] size;

		unionfind(int n) {
			p = new int[n];
			size = new int[n];

			for (int i = 0; i < n; i++) {
				p[i] = i;
			}
			Arrays.fill(size, 1);
		}

		int findSet(int v) {
			if (v == p[v])
				return v;
			return p[v] = findSet(p[v]);
		}

		boolean sameSet(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return true;
			return false;
		}

		int max() {
			int max = 0;
			for (int i = 0; i < size.length; i++)
				if (size[i] > max)
					max = size[i];
			return max;
		}

		void combine(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return;
			if (size[a] > size[b]) {
				p[b] = a;
				size[a] += size[b];

			} else {
				p[a] = b;
				size[b] += size[a];
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}