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.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.PriorityQueue;

public class Main {

	private static final String NO = "No";
	private static final String YES = "Yes";
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	private static final long MOD = 998244353;
	static int MAXN = 10;

	void solve() {
		int T = 1;// ni();

		for (int i = 0; i < T; i++)
			solve(i);
	}

	void solve(int nth) {
		int n = ni();
		int a[][] = new int[n][2];
		for (int i = 0; i < n; i++)
			a[i][0] = ni();
		for (int i = 0; i < n; i++)
			a[i][1] = ni();
		Arrays.sort(a, (x, y) -> x[0] - y[0]);
		long sum = 0, ans = 0;
		int last = 0, cur = -1;
		PriorityQueue<Integer> qu = new PriorityQueue<Integer>(Comparator.reverseOrder());
		while (!qu.isEmpty() || last < n) {
			if (!qu.isEmpty()) {
				sum -= qu.poll();
				ans += sum;
				cur++;
			} else
				cur = a[last][0];

			int pos = last;
			while (pos < n && a[pos][0] == cur) {
				qu.add(a[pos][1]);
				sum += a[pos][1];
				pos++;
			}
			last = pos;
		}
		out.println(ans);
	}

	// a^b
	long power(long a, long b) {
		long x = 1, y = a;
		while (b > 0) {
			if (b % 2 != 0) {
				x = (x * y) % MOD;
			}
			y = (y * y) % MOD;
			b /= 2;
		}
		return x % MOD;
	}

	private long gcd(long a, long b) {
		while (a != 0) {
			long tmp = b % a;
			b = a;
			a = tmp;
		}
		return b;
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

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

	private 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++];
	}

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

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

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private char[] nc(int n) {
		char[] ret = new char[n];
		for (int i = 0; i < n; i++)
			ret[i] = nc();
		return ret;
	}

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

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

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

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private Integer[] na2(int n) {
		Integer[] a = new Integer[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int[][] na(int n, int m) {
		int[][] a = new int[n][];
		for (int i = 0; i < n; i++)
			a[i] = na(m);
		return a;
	}

	private int ni() {
		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();
		}
	}

	private Long[] nl2(int n) {
		Long[] a = new Long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}

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

	private long[][] nl(int n, int m) {
		long[][] a = new long[n][];
		for (int i = 0; i < n; i++)
			a[i] = nl(m);
		return a;
	}

	private long nl() {
		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();
		}
	}

	public static class IterablePermutation implements Iterable<int[]>, Iterator<int[]> {
		int[] a;
		boolean first = true;

		public IterablePermutation(int n) {
			assert n >= 1;
			a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = i;
		}

		public IterablePermutation(int... a) {
			this.a = Arrays.copyOf(a, a.length);
		}

		@Override
		public boolean hasNext() {
			if (first)
				return true;
			int n = a.length;
			int i;
			for (i = n - 2; i >= 0 && a[i] >= a[i + 1]; i--)
				;
			return i != -1;
		}

		@Override
		public int[] next() {
			if (first) {
				first = false;
				return a;
			}
			int n = a.length;
			int i;
			for (i = n - 2; i >= 0 && a[i] >= a[i + 1]; i--)
				;
			assert i != -1;
			int j;
			for (j = i + 1; j < n && a[i] < a[j]; j++)
				;
			int d = a[i];
			a[i] = a[j - 1];
			a[j - 1] = d;
			for (int p = i + 1, q = n - 1; p < q; p++, q--) {
				d = a[p];
				a[p] = a[q];
				a[q] = d;
			}
			return a;
		}

		@Override
		public Iterator<int[]> iterator() {
			return this;
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

}
