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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.TreeMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DRecommendations solver = new DRecommendations();
        solver.solve(1, in, out);
        out.close();
    }

    static class DRecommendations {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt();
            int[] a = new int[n], t = new int[n];
            MultiSet<Integer> cur = new MultiSet<>();
            TreeMap<Integer, ArrayList<Integer>> val = new TreeMap<>();
            for (int i = 0; i < n; i++) a[i] = s.nextInt();
            for (int i = 0; i < n; i++) {
                t[i] = s.nextInt();
                if (!val.containsKey(a[i])) {
                    ArrayList<Integer> aa = new ArrayList<>();
                    aa.add(t[i]);
                    val.put(a[i], aa);
                } else val.get(a[i]).add(t[i]);
            }
            long ans = 0, tot = 0;
            for (Map.Entry<Integer, ArrayList<Integer>> e : val.entrySet()) {
                int next = e.getKey() + 1;
                ans += tot;
                for (int i = 0; i < e.getValue().size(); i++) {
                    cur.add(e.getValue().get(i));
                    tot += e.getValue().get(i);
                }
                int i = cur.t.lastKey();
                tot -= i;
                cur.remove(i);
                while (!cur.t.isEmpty() && !val.containsKey(next)) {
                    //w.println(e.getKey()+" "+next+" "+cur.t.firstKey());
                    i = cur.t.lastKey();
                    ans += tot;
                    tot -= i;
                    cur.remove(i);
                    next++;
                }
            }
            w.println(ans);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class MultiSet<U extends Comparable<U>> {
        int sz = 0;
        public TreeMap<U, Integer> t;

        public MultiSet() {
            t = new TreeMap<>();
        }

        public void add(U x) {
            t.put(x, t.getOrDefault(x, 0) + 1);
            sz++;
        }

        public void remove(U x) {
            if (t.get(x) == 1) t.remove(x);
            else t.replace(x, t.get(x) - 1);
            sz--;
        }

    }
}

