#include <bits/stdc++.h>
using namespace std;

using ll = long long;
int main() {
	int n;
	cin>>n;
	vector<int>a(n),c(n);
    for(int i = 0; i < n; i++){
    cin >> a[i];
}

for(int i = 0; i < n; i++){
    cin >> c[i];
}
    
    vector<pair<ll,ll>>b;
    
    for(int i = 0;i < n ;i++){
      b.push_back({a[i],c[i]});  	
    }
    sort(b.begin(),b.end());
    
    ll ans = 0;
    ll prev = -1;

    int i = 0;
    while(i<b.size()){
      int j = i;
      
      while(j<b.size() && b[j].first == b[i].first){
      	j++;
      }
      
       vector<ll> costs;
       
        for (int k = i; k < j; k++) {
            costs.push_back(b[k].second);
        }

        // Largest cost gets smallest increment
        sort(costs.rbegin(), costs.rend());

        ll start = max(b[i].first,prev+1);
        
        for(int k = 0 ; k < (int)costs.size();k++){
        	ll x = start + k;
        	
        	ans += (x - b[i].first)*costs[k];
        	prev = x;
        }
      
        i = j;
    	}
    
    
    cout<<ans<<endl;
}