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.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
 
 public class realfast implements Runnable {
    private static final int INF = (int) 1e9;
    long in= (long)Math.pow(10,9);
    public  void solve() throws IOException 
    {
       int n = readInt();
        
        cato arr[] = new cato[n];
        for(int i =0;i<n;i++)
            arr[i]= new cato(0,0);
        for(int i =0;i<n;i++)
            arr[i].a=readInt();
        for(int i =0;i<n;i++)
            arr[i].t=readInt();
        Arrays.sort(arr);

        int size =0;
        long time =0;
        long cost = 0;
        int seg[]= new int [800004];
    

        add(seg,1,100000,0,arr[0].t);
        size=1;
        time=arr[0].t;
        
        for(int i =1;i<n;i++)
        {
            int count=arr[i].a-arr[i-1].a;
            
            while(count>0&&size>0)
            {
                int val = delete(seg,1,100000,0);
            
                 time = time-val;
                  cost= cost+ time;               
                 size--;
                 count--;
            }
           
            size++;
            time=time+arr[i].t;
            add(seg,1,100000,0,arr[i].t);
        }

        while(size>0)
        {
           int val = delete(seg,1,100000,0);
        
           time =time-val;
           cost=cost+time; 
           size--;
        }
        
        out.println(cost);
     
    }
    public void add(int seg[], int left, int right , int index,int val)
    {
        if(left==right)
        {
            seg[index]++;
            return ;
        }
        seg[index]++;
        int mid = left+(right-left)/2;
        if(val<=mid)
            add(seg, left,mid,2*index+1,val);
        else
            add(seg,mid+1,right,2*index+2,val);
    }  
    public int delete(int seg[], int left, int right , int index)
    {
     
       if(left==right)
       {
         seg[index]--;
         return left;
       }
       seg[index]--;
       int mid = left +(right-left)/2;
       int val = seg[2*index+1];
       int val2 = seg[2*index+2];
       if(val2>0)
       {
        
       return delete(seg, mid+1,right, 2*index+2);
       }
       else
       {
        
       return delete(seg,left,mid,2*index+1);
       }   
    }   
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static void main(String[] args) {
        new Thread(null, new realfast(), "", 128 * (1L << 20)).start();
    }
 
    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    private PrintWriter out;
 
    @Override
    public void run() {
        try {
            if (ONLINE_JUDGE || !new File("input.txt").exists()) {
                reader = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                reader = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            }
            solve();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // nothing
            }
            out.close();
        }
    }
 
    private String readString() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
 
    @SuppressWarnings("unused")
    private int readInt() throws IOException {
        return Integer.parseInt(readString());
    }
 
    @SuppressWarnings("unused")
    private long readLong() throws IOException {
        return Long.parseLong(readString());
    }
 
    @SuppressWarnings("unused")
    private double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
}
class cato implements Comparable<cato>{
    int a;
    int t;
    
    cato(int u1, int v1 )
    {
       this.a=u1;
       this.t=v1;
       
    }
    public int compareTo(cato e)
    {
        return this.a-e.a;
    }
}
