#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n], b[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  multiset<long long> ms;
  map<long long, vector<long long>> mp;
  for (long long i = 0; i < n; i++) mp[a[i]].push_back(b[i]);
  auto it = mp.begin();
  long long ans = 0, sum = 0;
  while (it != mp.end()) {
    long long pos = it->first;
    auto nxt = it;
    nxt++;
    long long nxt_pos = nxt == mp.end() ? (long long)(1e17 + 10) : nxt->first;
    for (auto i : (it->second)) {
      ms.insert(-i);
      sum += i;
    }
    sum += *ms.begin();
    ms.erase(ms.begin());
    long long cur_pos = pos + 1;
    while (!ms.empty()) {
      if (cur_pos == nxt_pos) {
        ans += sum * (nxt_pos - pos);
        break;
      } else {
        auto itr = ms.begin();
        long long ind = *itr;
        ans -= ind * (cur_pos - pos);
        sum += ind;
        ms.erase(itr);
        cur_pos++;
      }
    }
    it++;
  }
  cout << ans;
  return 0;
}
