#include <bits/stdc++.h>
using namespace std;
long long Mod = 1e9 + 7;
long long poww(long long a, long long b, long long mod) {
  long long res = 1;
  if (b < 0) b = (b % (mod - 1) + mod - 1) % (mod - 1);
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) res = 1ll * res * a % mod;
  return res;
}
void Max(long long& x, long long y) { x = max(x, y); }
void Min(long long& x, long long y) { x = min(x, y); }
long long Add(long long x, long long y) {
  x %= Mod;
  y %= Mod;
  return (x + y) % Mod;
}
const long long N = 200200, K = 14, Inf = 4e15;
long long n, Cnt[N];
pair<long long, long long> a[N];
map<long long, multiset<long long>> m;
multiset<long long> tmp;
multiset<long long>::iterator it, ti, tt;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i].second;
    m[a[i].first].insert(a[i].second);
  }
  long long Ans = 0, Sum = 0, x = 0;
  for (auto p : m) {
    if (!tmp.empty()) {
      tt = (tmp.end());
      tt--;
      x = *tt;
    }
    if (p.second.size() == 1 && x == 0) continue;
    long long last = 0;
    for (it = p.second.begin(); it != p.second.end(); it++) {
      Sum += *it;
      tmp.insert(*it);
    }
    ti = tmp.end();
    ti--;
    Sum -= *ti;
    tmp.erase(ti);
    Ans += Sum;
    m[p.first + 1].insert(0);
  }
  cout << Ans << '\n';
  return 0;
}
