#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (!y) return x;
  return gcd(y, x % y);
}
const long long MOD = 1e9 + 7;
int inf = 1e9 + 7;
long long INF = 2e18 + 9;
long long power(long long x, long long y) {
  long long res = 1ll;
  x %= MOD;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % MOD;
    y = y >> 1ll;
    x = (x * x) % MOD;
  }
  return res;
}
long long inv(long long x) {
  long long r = 1ll, t = x, k = MOD - 2ll;
  while (k) {
    if (k & 1ll) r = (long long)r * t % MOD;
    t = (long long)t * t % MOD;
    k >>= 1;
  }
  return r;
}
bool isPrime(long long x) {
  if (x == 1) return false;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
const int nax = 5e5 + 13;
void prep() {}
void solve() {}
void read() {
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
  }
  long long ans = 0;
  sort(a.begin(), a.end());
  multiset<long long> s;
  long long sum = 0;
  int akt = a[0].first;
  for (int i = 0; i < n; i++) {
    if (a[i].first == akt) {
      s.insert(a[i].second);
      sum += a[i].second;
    } else {
      while (s.size() && akt != a[i].first) {
        sum -= (*s.rbegin());
        ans += sum;
        s.erase(s.find(*s.rbegin()));
        akt++;
      }
      akt = a[i].first;
      sum += a[i].second;
      s.insert(a[i].second);
    }
  }
  while (s.size()) {
    sum -= ((*s.rbegin()));
    ans += sum;
    s.erase(s.find(*s.rbegin()));
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  srand(time(NULL));
  int T = 1;
  prep();
  for (int i = 1; i <= T; i++) {
    read();
    solve();
  }
  return 0;
}
