#include <bits/stdc++.h>
using namespace std;
map<long long, vector<long long> > mp;
long long a[200005];
long long t[200005];
set<long long> s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i], s.insert(a[i]);
  for (long long i = 0; i < n; i++) {
    cin >> t[i];
    mp[a[i]].push_back(t[i]);
  }
  for (auto i : s) sort(mp[i].begin(), mp[i].end());
  long long ans = 0;
  multiset<long long> temp;
  long long sum = 0;
  while (s.size()) {
    long long v = *s.begin();
    s.erase(s.begin());
    for (auto i : mp[v]) temp.insert(i), sum += i;
    auto p = s.lower_bound(v);
    long long nex = 1e18;
    if (p != s.end()) nex = *p;
    long long d = nex - v;
    long long siz = min(d, (long long)temp.size());
    long long c = 0;
    while (siz--) {
      auto po = prev(temp.end());
      ans += (*po) * c;
      c++;
      sum -= (*po);
      temp.erase(po);
    }
    ans += sum * c;
  }
  cout << ans;
}
