#include <bits/stdc++.h>
using namespace std;
void func() {
  long long n;
  cin >> n;
  std::vector<pair<long long, long long> > v(n);
  for (long long i = 0; i < n; ++i) {
    cin >> v[i].first;
  }
  for (long long i = 0; i < n; ++i) {
    cin >> v[i].second;
  }
  sort(v.begin(), v.end());
  multiset<long long> s;
  long long i = 0, ans = 0, sum = 0, cur = v[0].first;
  while (i < n || !s.empty()) {
    while (v[i].first == cur && i < n) {
      s.insert(v[i].second);
      sum += v[i].second;
      ++i;
    }
    if (!s.empty()) {
      long long x = *s.rbegin();
      sum -= x;
      ans += sum;
      s.erase(s.find(x));
      cur++;
    } else {
      cur = v[i].first;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    func();
  }
}
