#include <bits/stdc++.h>
using namespace std;
void USACO(string s) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const long long mod = 1e9 + 7;
const long long MAXN = 100010;
void solve() {
  pair<int, int> p[200005];
  int i, n;
  cin >> n;
  for (i = 0; i < n; i++) cin >> p[i].first;
  for (i = 0; i < n; i++) cin >> p[i].second;
  sort(p, p + n);
  priority_queue<int> pq;
  long long ans = 0, sum = 0;
  i = 0;
  int cur = p[i].first;
  while (i < n || pq.size()) {
    if (pq.size() == 0) cur = p[i].first;
    while (i < n && cur == p[i].first) {
      pq.push(p[i].second);
      sum += p[i].second;
      i++;
    }
    sum -= pq.top();
    pq.pop();
    ans += sum;
    cur++;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
