#include <bits/stdc++.h>
using namespace std;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
void solve(int qq) {
  int n;
  cin >> n;
  vector<long long> a(n), cost(n);
  multiset<long long> s;
  long long sum = 0, ans = 0;
  vector<pair<long long, int> > to;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    to.push_back(make_pair(a[i], i));
  }
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
  }
  sort((to).begin(), (to).end());
  int j = 0;
  long long cur = to[j].first;
  while (!s.empty() || j < n) {
    if (j < n && s.empty()) {
      cur = to[j].first;
    }
    while (j < n && to[j].first == cur) {
      s.insert(cost[to[j].second]);
      sum += cost[to[j].second];
      j++;
    }
    while (!s.empty() && ((j < n && cur < to[j].first) || j >= n)) {
      long long rem = *s.rbegin();
      sum -= *s.rbegin();
      s.erase(s.find(rem));
      ans += sum;
      cur++;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  return 0;
}
