#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long int a[200005], b[200005];
int main() {
  long long int n, i, j;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  while (cin >> n) {
    for (i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (i = 1; i <= n; i++) {
      cin >> b[i];
    }
    vector<pair<long long int, long long int> > v;
    for (i = 1; i <= n; i++) v.push_back(make_pair(a[i], b[i]));
    v.push_back(make_pair(2000000000000000000, 2000000000000000000));
    long long int ans = 0;
    priority_queue<long long int> pq;
    long long int sum = 0;
    sort(v.begin(), v.end());
    for (i = 0; i < v.size() - 1; i++) {
      long long int cn1 = 0;
      vector<long long int> v1;
      for (j = i; j < v.size(); j++) {
        if (v[i].first != v[j].first) break;
        v1.push_back(v[j].second);
      }
      long long int x = v[i].first + pq.size() + v1.size();
      for (long long int k = 0; k < v1.size(); k++) {
        sum += v1[k];
        pq.push(v1[k]);
      }
      if (x > v[j].first) {
        long long int y = v[j].first - v[i].first;
        while (y > 0) {
          sum -= pq.top();
          pq.pop();
          ans += sum;
          y--;
        }
      } else {
        while (pq.size() > 0) {
          sum -= pq.top();
          pq.pop();
          ans += sum;
        }
      }
      i = j - 1;
    }
    cout << ans << endl;
  }
  return 0;
}
