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.util.*;
import java.io.*;
public class template {
	final static int MOD = 1000000007;
	final static int intMax = 1000000000;
	final static int intMin = -1000000000;
	final static int[] DX = { 0, 0, -1, 1 };
	final static int[] DY = { -1, 1, 0, 0 };

	static int T;

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[360]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}
	public static void main(String[] args) throws Exception {
		Reader in = new Reader();
		int n = in.nextInt();
		pub[] p = new pub[n + 1];
		int[] a = new int[n];
		int[] t = new int[n];
		for(int i = 0; i < n; ++i) {
			a[i] = in.nextInt();
		}
		for(int i = 0; i < n; ++i) {
			t[i] = in.nextInt();
		}
		for(int i = 0; i < n; ++i) {
			p[i] = new pub(a[i], t[i]);
		}
		p[n] = new pub(Integer.MAX_VALUE, Integer.MAX_VALUE);
		Arrays.sort(p, (x, y) -> x.a == y.a ? y.t - x.t : x.a - y.a);
		HashSet<Integer> passed = new HashSet<Integer>();
		PriorityQueue<pub> q = new PriorityQueue<pub>((x, y) -> y.t - x.t);
		long sum = 0, tot = 0;
		for(int i = 0; i < n; ++i) {
			sum += tot;
			if(q.size() > 0) {
				if(p[i].t < q.peek().t) {
					tot -= q.poll().t;
					tot += p[i].t;
					q.add(p[i]);
				}
			}
			int ind = i + 1;
			while(ind < n && p[ind].a == p[i].a) {
				q.add(p[ind]);
				tot += p[ind++].t;
			}
			i = ind - 1;
			for(int j = p[i].a + 1; j < p[i + 1].a && q.size() > 0; ++j) {
				sum += tot;
				tot -= q.poll().t;
			}
		}
		System.out.println(sum);
		in.close();
	}
	static class pub{
		int a, t;
		pub(int ai, int ti){
			a = ai; t = ti;
		}
		public String toString() {
			return a + " " + t;
		}
	}
}