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.*;
import java.math.BigInteger;

public class D1315{
    static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        if (b == 0) 
            return a; 
        int k; 
        for (k = 0; ((a | b) & 1) == 0; ++k)  
        { 
            a >>= 1; 
            b >>= 1; 
        } 
        while ((a & 1) == 0) 
            a >>= 1; 

        do { 
            while ((b & 1) == 0) 
                b >>= 1; 
            if (a > b)  
            { 
                int temp = a; 
                a = b; 
                b = temp; 
            } 

            b = (b - a); 
        } while (b != 0); 
        return a << k; 
    }   
    static int lcm(int a,int b){
        return a*b/gcd(a,b);
    }
	public static int binary(int arr[],int n, int a,int beg,int end){
		while(beg<=end){
			int mid=beg+(end-beg)/2;
			if(arr[mid]==a)
				return mid;
			if(arr[mid]<a)
				end=mid-1;
			else
				beg=mid+1;
		}
		return -1;
	}
    
    public static int binaryless(int arr[],int n, int a,int beg,int end){
        while(beg<=end){
            int mid=beg+(end-beg)/2;
            if(arr[mid]>=a){
                if(mid==1||arr[mid-1]<a)
                    return mid;
                end=mid-1;
            }
            else{
                beg=mid+1;
            }
        }
        return -1;
    }
	public static void sieve(int t){
		boolean srr[]=new boolean[t+1];
        
        for(int i=2;i*i<=t;i++)
        {
            if(!srr[i])
            {
                for(int k=i*i;k<=t;k+=i)
                    srr[k]=true;
            }
        }
        for(int i=2;i<t+1;i++){
        	if(!srr[i])
            	System.out.println(i);
        }
	}
    static int power(int x, int y, int p) 
    { 
        int res = 1;      
        x = x % p;  
        while (y > 0) 
        { 
            if((y & 1)==1) 
                res = (res * x) % p; 
            y = y >> 1;  
            x = (x * x) % p;  
        } 
        return res; 
    } 
    
    static class Custom implements Comparable<Custom>{
        int d;
        int f;
        public Custom(int d,int f){
            this.d=d;
            this.f=f;
        }
        public Custom(){
            

        }
        public int compareTo(Custom t){
            if(this.d!=t.d)
            return this.d-t.d;
        return t.f-this.f;
        }
    }
    void solve() throws IOException {
        
        int n=nextInt();
        
        Custom arr[]=new Custom[n];
        
        for(int i=0;i<n;i++){
            arr[i]=new Custom();
            arr[i].d=nextInt();  
        }
        for(int i=0;i<n;i++){
            arr[i].f=nextInt();  
        }
        Arrays.sort(arr);
        PriorityQueue<Integer> pq= new PriorityQueue<>(new Comparator<Integer>(){
            public int compare(Integer a,Integer b){
                return b-a;
            }
        });
        long sum=0;
        long ans=0;
        for(int i=1;i<n;i++){
            // System.out.println("DSv");
            if(arr[i].d==arr[i-1].d){
                // System.out.println("DSscfdv");
                pq.add(arr[i].f);
                sum+=arr[i].f;
            }
            else{
                // System.out.println("DSvsads");
                for(int j=arr[i-1].d+1;j<arr[i].d&&pq.size()>0;j++){
                    ans+=sum;
                    sum-=pq.poll();
                }
                if(pq.size()>0){
                    
                        ans+=sum;
                    if(pq.peek()>arr[i].f){
                        sum-=pq.poll();
                        sum+=arr[i].f;
                        pq.add(arr[i].f);
                    }

                }
                

            }
            // System.out.println(ans+" "+pq);
        }
        for(int j=arr[n-1].d+1;pq.size()>0;j++){
            ans+=sum;
            sum-=pq.poll();
        }
        pw.println(ans);
    }
	String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    String nextLine()throws IOException{
        return br.readLine();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    long nextLong() throws IOException {
        return Long.parseLong(next());
    }
 
    StringTokenizer st;
    BufferedReader br;
    PrintWriter pw;
    Scanner sc;
    void run() throws IOException {
        sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
        long time = System.currentTimeMillis();
        solve();
        System.err.println("time = " + (System.currentTimeMillis() - time));
        pw.close();
    }
 
    public static void main(String[] args) throws IOException {
        new D1315().run();
    }
 
}