5
1000000000 1000000000 1000000000 1000000000 1000000000
100000 100000 100000 100000 100000
 10
14 31 50 67 42 44 86 82 35 63
76 17 26 44 60 54 50 73 71 70
 10
4 4 1 2 2 2 5 4 1 5
28 81 36 44 2 40 39 43 36 33
 10
69564153 558821634 273092444 121621442 354953668 157021146 918149509 902159900 772175415 945981912
29 26 22 78 90 35 24 75 52 53
 1
743365444
98
 5
298137706 371378543 159326899 423775489 643749813
1 90 76 23 14
 5
2 52 60 67 26
51 96 75 41 88
 2
8 4
57 28
 5
12 4 19 18 19
15467 14873 66248 58962 90842
 1
380100964
63923
 2
3 2
55839 83916
 2
1000000000 1000000000
100000 100000
 2
5 3
96 59
 1
4
85648
 2
84 18
96 92
 5
4 2 4 3 3
8 9 34 54 14
 1
23
29532
 2
759394108 613490963
19556 57005
 1
1000000000
100000
 2
624526990 51492804
74 4
 1
1
72
 1
5
16
 2
86 67
77701 9079
 2
7 6
2374 9808
 5
487208130 193137490 653652531 77955217 628457798
37995 12724 66478 45619 87697
 1
204
74562
 5
82 90 21 10 3
37195 83314 87379 83209 32491
 5
3 10 9 5 8
12157 40766 83283 22455 29741
 10
1 4 2 3 5 1 3 5 4 2
95757 10134 79392 48220 34450 34587 61472 88154 76492 38800
 5
8 2 3 10 1
2 37 19 73 60
 1
3
31
 10
2 2 2 6 4 4 10 2 2 8
18 13 94 43 72 62 23 47 94 41
 10
97 75 68 98 56 44 68 24 40 18
75753 53146 17573 59200 87853 73083 67536 45475 70260 99681
 40
19 20 8 13 13 17 1 14 15 20 14 17 2 9 9 10 19 16 6 12 9 7 20 5 12 6 4 4 12 5 4 11 8 1 2 8 11 19 18 4
52258 5648 46847 9200 63940 79328 64407 54479 1788 60107 8234 64215 15419 84411 50307 78075 92548 17867 43456 7970 1390 99373 97297 90662 82950 678 79356 51351 2794 82477 16508 19254 81295 9711 72350 11578 21595 69230 82626 25134
 10
400625724 498124775 960958038 697226708 233136478 292118728 33139194 339478293 914271877 828083523
9789 90524 51162 97707 59267 60261 43260 60358 64419 44097
 10
2 5 1 9 1 2 7 8 1 10
38888 43309 35602 62895 51161 96523 20607 20309 21976 21231
 10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
100000 100000 100000 100000 100000 100000 100000 100000 100000 100000
 5
1 5 1 2 1
49027 92184 18591 86401 84238
 1
1
40825

1000000
 0
 593
 0
 0
 0
 0
 0
 66248
 0
 0
 100000
 0
 0
 0
 44
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 779373
 0
 0
 630
 17573
 6113465
 0
 255574
 4500000
 153827
 0

//package cf;
import java.io.*;
import java.util.*;

public class T_class {
    static int m=2147483647;///this is 2^32 -1 (is prime number) and should be used for hashing
    static int p=1000000007;
    static int max=(int)2e3+10;
    static boolean prime[]=new boolean[max+5];
    static  int dp[][]=new int[(int)max][max];
    static  List<Integer> total_prime=new ArrayList<>();
    public static class pr
    {
        int ai;
        int ti;
        pr(int a,int b)
        {
            ai=a;
            ti=b;
        }
    }
    public static void main(String[] args) throws Exception {
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();
        int t=1;
        StringBuilder sb2=new StringBuilder();

        while(t-- >0) {
            int n=sc.nextInt();
            List<pr> l1=new ArrayList<>();
            int ar[]=new int[n];
            int br[]=new int[n];
            HashMap<Integer,Integer> set=new HashMap<>();
            Set<Integer> it=new HashSet<>();
            for(int i=0;i<n;i++) {
            ar[i]=sc.nextInt();
                set.put(ar[i],set.getOrDefault(ar[i],0)+1);
                it.add(ar[i]);
            }
            for(int i=0;i<n;i++) {
                br[i]=sc.nextInt();
            }
            for(int i:it)
            {
                if(set.get(i)==1)
                    set.remove(i);
            }
            long s=0;
            for(int i=0;i<n;i++)
            {
                int a=ar[i];
                if(set.containsKey(a)) {
                    pr cur = new pr(a, br[i]);
                    l1.add(cur);
                }
                //set.put(a,set.getOrDefault(a,0)+1);
            }
            Collections.sort(l1, new Comparator<pr>() {
                @Override
                public int compare(pr o1, pr o2) {
                    return o1.ti-o2.ti;
                }
            });/*
            for(pr i:l1)
            {
                System.out.println(i.ai+" "+i.ti);
            }*/
            set.clear();
            for(int i=0;i<n;i++) {
                set.put(ar[i],set.getOrDefault(ar[i],0)+1);
                it.add(ar[i]);
            }
            for(int i=0;i<l1.size();i++)
            {
                pr cur=l1.get(0);
                long cur_cst=cur.ti;
                int cur_ai=cur.ai;
                long cur_s=0;
                //System.out.println(cur_ai+" "+set+" "+set.get(cur_ai));
                set.put(cur_ai,set.getOrDefault(cur_ai,0)-1);
               // System.out.println(cur_ai+" "+set+" "+set.get(cur_ai));
                while(set.containsKey(cur_ai)&&set.get(cur_ai)>0)
                {
                    cur_ai++;
                    cur_s+=cur_cst;
                }
               // System.out.println(set);
               // System.out.println(cur_ai+" in "+cur_s);
                set.put(cur_ai,set.getOrDefault(cur_ai,0)+1);
                s+=cur_s;
            }
            sb2.append(s);
        }
        System.out.println(sb2.toString());
        out.flush();
    }
    public static long gethash(long pow[], long hash[], int l, int r) {

        return (hash[r+1] - (hash[l ] * pow[r - l +1]) % m + m) % m;
    }
    private static String long_pre(char[] ch) {
        int n=ch.length;
        char cpy[]=new char[n];
        for(int i=n-1;i>=0;i--)
        {
            cpy[n-1-i]=ch[i];
        }
        long pow[] = new long[n + 1];
        long hash[] = new long[n + 1];
        pow[0] = 1;
        int p = 31;
        for (int i = 1; i <= n; i++) {
            pow[i] = (pow[i - 1] % m * p % m) % m;
        }

        for (int i = 1; i <= n; i++) {
            hash[i] = (hash[i - 1] * p % m + (ch[i - 1]) % m) % m;
        }

        long pow1[] = new long[n + 1];
        long hash1[] = new long[n + 1];
        pow1[0] = 1;
        //int p = 31;
        for (int i = 1; i <= n; i++) {
            pow1[i] = (pow1[i - 1] % m * p % m) % m;
        }

        for (int i = 1; i <= n; i++) {
            hash1[i] = (hash1[i - 1] * p % m + (cpy[i - 1]) % m) % m;
        }


        int l=0,r=n-1,lst=0;
        for(int i=n-1;i>=1;i--)
        {
        int mid=i%2;
        int midp=i/2;
        if(mid==0&&gethash(pow,hash,0,midp-1)==gethash(pow1,hash1,n-1-i,n-1-(midp+1)))
        {
            lst=i;
            break;
        }
        else if(mid==1&&gethash(pow,hash,0,midp)==gethash(pow1,hash1,n-1-i,n-1-(midp+1)))
        {
            lst=i;
            break;
        }
        }
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<=lst;i++)
        {
            sb.append(ch[i]);
        }
        return sb.toString();
    }

    private static int Solve(int n, int l, int r,int h, int i, int s, int[] ar) {
        if(i==n)
            return 0;
        if(dp[i][s]!=-1)
            return dp[i][s];

        int ans=Math.max(con((s+ar[i])%h,l,r)+Solve(n,l,r, h,i+1,(s+ar[i])%h,ar)
                ,con((s+ar[i]-1)%h,l,r)+Solve(n,l,r,h,i+1,(s+ar[i]-1+h)%h,ar));
        dp[i][s]=ans;
        return dp[i][s];
    }

    private static int con(int i,int l,int r) {
        if(l<=i&&i<=r)
            return 1;
        else
            return 0;
    }

    static  long childs[]=new long[max];
    static long tot=0;
    public static void dfs_val(List<Integer> adj[],int u,int p,long val) {
        int in_max=-1;
        val=val+childs[u]+1;
        for(int v:adj[u])
        {
            if(v!=p)
            {
                in_max=v;
                dfs_val(adj,v,p,val);
            }
        }
        if(in_max==-1)
        {
            tot=Math.max(tot,val);
        }
    }
    public static void dfs(List<Integer> adj[],int u,int p)
    {

        for(int v:adj[u])
        {
            if(v!=p)
            {
                childs[u]++;
                dfs(adj,v,u);
                childs[u]+=childs[v];
            }
        }
    }
    public static int ans(int ar[],int i,int n,int t)
    {
        if(i>=n)
            return 0;
        if(t>=410)
            return 200000;
        if(dp[i][t]!=-1)
            return dp[i][t];
        //System.out.println(t+" "+i);
        int cur=Math.min(Math.abs(ar[i]-t)+ans(ar,i+1,n,t+1),ans(ar,i,n,t+1));
        dp[i][t]=cur;
        return dp[i][t];
    }

    private static long ncr(int n, int r, long[] fact) {
        if(r>n||n < 0 || r < 0)
            return 0;

        if(n==1||n==0)
            return 1;
        // System.out.println(n+" c "+r);

        return (((fact[n]*pow_inverse(fact[n-r],p))%p)*pow_inverse(fact[r],p))%p;
    }
    static class BIT {
        long[] tree;
        public BIT(int size) {
            tree = new long[size + 1];
        }
        public long sum(int i) {
            long ans = 0;
            while (i > 0) {
                ans += tree[i];
                i -= i & -i;
            }
            return ans;
        }

        public long query(int i, int j) {
            return sum(j) - sum(i - 1);
        }

        public void add(int i, long val) {
            while (i < tree.length) {
                tree[i] += val;
                i += i & -i;
            }
        }

        public void set(int i, long val) {
            add(i, val - query(i, i));
        }
    }
    static class  vert implements Comparator<vert>
    {
        int v;
        TreeSet<Integer> set;

        public vert(int v, TreeSet<Integer> set) {
            this.v = v;
            this.set = set;
        }

        @Override
        public int compare(vert o1, vert o2) {
            return -(o1.set.size()-o2.set.size());
        }
    }
    public static long pow(long a,long b,long m)
    {
        long r=1;
        while(b!=1)
        {
            if(b%2!=0)
                r=(r*a)%m;
            b=b>>1;
            a=(a*a)%m;
        }
        return (r*a)%m;
    }
    public static long pow_inverse(long a,long m)
    {
        return pow(a,m-2,m);
    }public static long gcd(long a,long b)
    {
        if(b>a)
        {
            a=a^b;
            b=a^b;
            a=a^b;
        }
        if(b==0)
            return a;
        return gcd(b,a%b);
    }
    public static void extgcd(long a,long b)
    {/*
            if(a==0)
            {
                x=0;
                y=1;
                d=b;
                // return ;
            }
            else
            {

                extgcd(b%a,a);

                long t=y;
                y=x;
                x=t-(b/a)*x;
            }*/
    }

    public static void seive()
    {
        for(int i=0;i<max;i++)
            prime[i] = true;

        for(int p = 2; p*p <=max; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if(prime[p] == true)
            {
                // Update all multiples of p
                for(int i = p*p; i <=max; i += p)
                    prime[i] = false;
            }
        }

        // Print all prime numbers
        for(int i = 2; i <= max; i++)
        {
            if(prime[i] == true)
            {
                total_prime.add(i);
            }
        }
    }
    public static boolean union(int a, int b, int p[], int r[]){
        // add your code here
        int pa=find(a,p,r);
        int pb=find(b,p,r);
        if(pa==pb)
            return true;
        if(pa!=pb)
        {
            if(r[pa]<r[pb])
            {
                p[pa]=pb;
            }
            else if(r[pa]>r[pb])
            {
                p[pb]=pa;
            }
            else
            {
                p[pa]=pb;
                r[pb]++;
            }
        }
        return false;
    }
    public static int find(int x,int p[],int r[])
    {
        if(p[x]==x)
            return x;
        p[x]=find(p[x],p,r);
        return p[x];
    }
    public static int binary_Search_upper(Integer[] ar, Integer x,int l,int r)
    {
        int res=-1,f=0;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(ar[mid]==x)
            {
                f=1;
                res=mid;
                l=mid+1;
            }
            else if(ar[mid]>x)
            {
                res=res!=-1&&ar[res]==x?res:mid;
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        return f==1?res:res+1;
    }
    public static int binary_Search_lower(int[] ar, long x, int l, int r)
    {
        int res=0,f=0;
        //int l=0;int r=ar.length-1;
        /*public static int binary(Long[] ar, int l, int r, long v)
        {
            int n=r;
            int m=(l+r)/2;
            int re=-1;
            while(l<=r)
            {
                if(ar[m]>=v)
                {

                    re=m;
                    r=m-1;
                }
                else if(ar[m]<v)
                {
                    l=m+1;
                }
                m=(l+r)/2;
            }
            if(l<=n&&ar[l]==v)
                return l;
            return re;
        }*/
        //   System.out.println(Arrays.toString(ar)+" "+x);
        while(l<=r)
        {
            int mid=(l+r)>>1;
            //   System.out.println(l+" "+r+" "+mid+" = "+ar[mid]);
            if(ar[mid]==x)
            {
                f=1;
                res=mid;
                r=mid-1;
            }
            else if(ar[mid]>x)
            {
                r=mid-1;
            }
            else
            {
                res=res!=0&&ar[res]==x?res:mid;
                l=mid+1;
            }
        }

        //  System.out.println(res);
        return f==1?res:res+1;
    } public static int binary_Search_lower_suf(int[] ar, int x,int l,int r)
    {
        int res=-1,f=0;
        //int l=0;int r=ar.length-1;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(ar[mid]==x)
            {
                f=1;
                res=mid;
                r=mid-1;
            }
            else if(ar[mid]<x)
            {
                r=mid-1;
            }
            else
            {
                //      res=mid;
                l=mid+1;
            }
        }
        return f==0?res+1:res;
    }
    int bit[]=new int[(int)1e6];
    public void update(int n,int val,int i)
    {
        i++;
        while(i<n)
        {
            bit[i]+=val;
            i+=(i)&(-i);
        }

    }
    public long query(int n,int i)
    {
        i++;
        long sum=0;
        while(i>0)
        {
            sum+=bit[i];
            i-=(i)&(-i);
        }
        return sum;
    }


    ///////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }


}