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.*;
import java.lang.*;
import java.math.*;
public class Main extends Thread  {
    boolean[] prime;
    FastScanner sc;
    PrintWriter pw;
    long startTime = System.currentTimeMillis();
    final class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public long nlo() {
            return Long.parseLong(next());
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public String nli() {
            String line = "";
            if (st.hasMoreTokens()) line = st.nextToken();
            else try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            while (st.hasMoreTokens()) line += " " + st.nextToken();
            return line;
        }

        public double nd() {
            return Double.parseDouble(next());
        }
    }
    public Main(ThreadGroup t,Runnable r,String s,long d )
    {
        super(t,r,s,d);
    }
    public void run()
    {
        sc=new FastScanner();
        pw=new PrintWriter(System.out);
        solve();
        pw.flush();
        pw.close();
    }
    public static void main(String[] args)
    {
        new Main(null,null,"",1<<26).start();
    }


    /////////////------------------------------------//////////////
    ////////////------------------Main-Logic--------//////////////
    ///////////-------------------------------------//////////////
    class Pair implements Comparable<Pair>{
    long num;
    long tm;
    Pair(long x,long y)
    {
        num=x;
        tm=y;
    }
    public int compareTo(Pair b)
    {
        long p=b.tm-tm;
        if(p<0)
        return -1;
        if(p==0)
        return 0;
        else
        return 1;
    }
    }
    public void solve() {
        int t = 1;
        while(t-->0)
        {
           int n=sc.ni();
           int[] arr=new int[n];
           int[] brr=new int[n];
           for(int i=0;i<n;i++)
           arr[i]=sc.ni();
           for(int i=0;i<n;i++)
           brr[i]=sc.ni();
           TreeMap<Long,ArrayList<Pair>> map=new TreeMap<Long,ArrayList<Pair>>();
           for(int i=0;i<n;i++)
           {
               long x=arr[i];
               long y=brr[i];
               Pair p=new Pair(x,y);
               if(map.containsKey(x))
                   map.get(x).add(p);
                else
                {
                    ArrayList<Pair> lst=new ArrayList();
                    lst.add(p);
                    map.put(x,lst);
                }
           }
           long ans=0,to=0;
           PriorityQueue<Long> pq=new PriorityQueue(n,Collections.reverseOrder());
           while(map.size()>0)
           {
               long x=map.firstKey();
               ArrayList<Pair> list=map.get(x);
               for(Pair pp:list)
               {pq.add(pp.tm);to+=pp.tm;}
               if(pq.size()==1)
               {map.remove(x);to-=(pq.poll());continue;}
               if(map.higherKey(x)!=null)
               {
                   long kk=map.higherKey(x);
                  long k=x+1L;
                  to-=pq.poll();
                  while((k<kk)&&(pq.size()>0))
                  {
                      long kt=pq.poll();
                     // pw.println(x+" "+kt);
                      ans+=(kt*(k-x));
                      k+=1L;
                      to-=kt;
                  }
                  //pw.println(to+" "+" "+x);
                  ans+=(to*(kk-x));
               }
               else
               {
                  long k=x+1L;
                  to-=pq.poll();
                  while(!pq.isEmpty())
                  {
                      long g=pq.poll();
                      ans+=(g*(k-x));
                      k+=1L;
                  }
               }
               map.remove(x);
               //pw.println(ans+" "+pq.size()+" "+x);
           }
           pw.println(ans);
        }
    }
}