#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 5;
pair<int, int> a[N];
int n;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (auto i = (0); i < (n); i++) {
    cin >> a[i].first;
  }
  for (auto i = (0); i < (n); i++) cin >> a[i].second;
  sort(a, a + n);
  int ptr = 0;
  set<pair<int, int>, greater<pair<int, int> > > biggest;
  long long ans = 0;
  long long sum = 0;
  int curr = 0;
  for (auto i = (0); i < (n); i++) {
    if (!biggest.empty()) {
      ++curr;
    } else {
      curr = a[ptr].first;
      biggest.insert(make_pair(a[ptr].second, ptr));
      sum = a[ptr].second;
      ++ptr;
    }
    while (ptr < n && a[ptr].first == curr) {
      sum += a[ptr].second;
      biggest.insert(make_pair(a[ptr].second, ptr));
      ++ptr;
    }
    ans += sum - biggest.begin()->first;
    sum -= biggest.begin()->first;
    biggest.erase(biggest.begin());
  }
  cout << ans << endl;
  return 0;
}
