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 D implements Runnable {
	boolean judge = false;
	FastReader scn;
	PrintWriter out;
	String INPUT = "5\r\n" + 
			"3 7 10 7 9\r\n" + 
			"5 2 5 7 5\r\n" + 
			"";

	void solve() {
		int n = scn.nextInt();
		int[][] arr = new int[n][2];
		for (int i = 0; i < n; i++) {
			arr[i][0] = scn.nextInt();
		}
		for (int i = 0; i < n; i++) {
			arr[i][1] = scn.nextInt();
		}

		TreeMap<Integer, TreeMap<Integer, Integer>> list = new TreeMap<>();
		TreeMap<Integer, Long> s = new TreeMap<>();
		TreeMap<Integer, Integer> sz = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			if (!list.containsKey(arr[i][0])) {
				list.put(arr[i][0], new TreeMap<>());
			}
			list.get(arr[i][0]).merge(arr[i][1], 1, Integer::sum);
			s.merge(arr[i][0], (long) arr[i][1], Long::sum);
			sz.merge(arr[i][0], 1, Integer::sum);
		}

		int st = list.firstKey();
		long ans = 0, sum = s.get(st), size = sz.get(st);
		TreeMap<Integer, Integer> need = list.get(st);

		while (true) {
			if (size == 1) {
				if (list.higherKey(st) != null) {
					st = list.higherKey(st);
					need = list.get(st);
					sum = s.get(st);
					size = sz.get(st);
					continue;
				}
				break;
			}

			int last = need.lastKey();
			sum -= last;
			size--;
			need.merge(last, -1, Integer::sum);
			if (need.get(last) == 0) {
				need.remove(last);
			}

			if (list.higherKey(st) == null) {
				long j = 1;
				while (!need.isEmpty()) {
					int x = need.lastKey();
					int y = need.get(x);
					need.remove(x);

					long d = -j * (j - 1) / 2;
					j += y;
					d += j * (j - 1) / 2;
					ans += d * x;
				}
				break;
			}

			int nx = list.higherKey(st);

			int space = nx - st - 1;
			if (space >= size) {
				long j = 1;
				while (!need.isEmpty()) {
					int x = need.lastKey();
					int y = need.get(x);
					need.remove(x);

					long d = -j * (j - 1) / 2;
					j += y;
					d += j * (j - 1) / 2;
					ans += d * x;
				}
				st = nx;
				need = list.get(st);
				sum = s.get(st);
				size = sz.get(st);
			} else {
				long j = 1;
				while (space > 0) {
					int x = need.lastKey();
					int y = need.get(x);
					need.remove(x);

					if (space >= y) {
						sum -= x * 1L * y;
						size -= y;
						long d = -j * (j - 1) / 2;
						j += y;
						d += j * (j - 1) / 2;
						ans += d * x;
						
						space -= y;
					} else {
						sum -= x * 1L * space;
						size -= space;
						need.put(x, y - space);
						
						long d = -j * (j - 1) / 2;
						j += space;
						d += j * (j - 1) / 2;
						ans += d * x;
						
						space = 0;
					}
				}

				ans += sum * (nx - st);

				st = nx;
				TreeMap<Integer, Integer> map2 = list.get(st);
				sum += s.get(st);
				size += sz.get(st);
				
				if(need.size() < map2.size()) {
					for(int key : need.keySet()) {
						map2.merge(key, need.get(key), Integer::sum);
					}
					need = map2;
				} else {
					for(int key : map2.keySet()) {
						need.merge(key, map2.get(key), Integer::sum);
					}
				}
			}
		}
		out.println(ans);
	}

	ArrayList<Integer> merge(ArrayList<Integer> a, ArrayList<Integer> b) {
		ArrayList<Integer> rv = new ArrayList<Integer>();
		int p = 0, q = 0;
		while (p < a.size() && q < b.size()) {
			if (a.get(p) < b.get(q)) {
				rv.add(a.get(p));
				p++;
			} else {
				rv.add(b.get(q));
				q++;
			}
		}
		while (p < a.size()) {
			rv.add(a.get(p));
			p++;
		}
		while (q < b.size()) {
			rv.add(b.get(q));
			q++;
		}
		return rv;
	}

	public void run() {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null || judge;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) {
		new Thread(null, new D(), "Main", 1 << 28).start();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

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

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		String nextLine() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

		int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

		long[][] next2DLong(int n, int m) {
			long[][] arr = new long[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLongArray(m);
			}
			return arr;
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				int c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		long[] shuffle(long[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				long c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		int[] uniq(int[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			int[] rv = new int[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		long[] uniq(long[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			long[] rv = new long[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		int[] reverse(int[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		long[] reverse(long[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		int[] compress(int[] arr) {
			int n = arr.length;
			int[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}

		long[] compress(long[] arr) {
			int n = arr.length;
			long[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}
	}
}