#include <bits/stdc++.h>
using namespace std;
const long long MAX = 300005;
long long inf = (long long)1e13;
long long n, m, k;
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a, c;
  multiset<long long> nums;
  for (int i = 0; i < n; i++) {
    long long b;
    cin >> b;
    a.push_back({b, -1});
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
  }
  a.push_back({0, 0});
  sort(a.begin(), a.end());
  a.push_back({(long long)1e10, 0});
  long long ans = 0;
  long long mus = 0;
  for (int i = 1; i <= n + 1; i++) {
    long long cnt = 0;
    while (nums.size() && a[i - 1].first + cnt < a[i].first) {
      ans -= *(nums.rbegin());
      ans += mus;
      mus -= *(nums.rbegin());
      nums.erase(nums.find(*nums.rbegin()));
      cnt++;
    }
    nums.insert(a[i].second);
    mus += a[i].second;
  }
  cout << ans;
  return 0;
}
