#include <bits/stdc++.h>
const int N = 3 * 1e5 + 5;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
using namespace std;
long long int modpow(long long int x, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
long long int modFact(long long int n, long long int p) {
  if (n >= p) return 0;
  long long int result = 1;
  for (long long int i = 1; i <= n; i++) result = (result * i) % p;
  return result;
}
bool isPrime(int x) {
  if (x % 2 == 0) return 0;
  for (int i = 3; i <= sqrt(x); i += 2) {
    if (x % i == 0) return 0;
  }
  return 1;
}
void solve() {
  int n;
  cin >> n;
  std::vector<std::pair<int, int>> v;
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(make_pair(x, 0));
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    v[i].second = x;
  }
  sort(v.begin(), v.end());
  v.push_back(make_pair(INT_MAX, 1));
  set<pair<int, int>, greater<pair<int, int>>> s;
  int curr = -1;
  int c = -1;
  long long int ans = 0, sum = 0, total = 0;
  while (curr < n) {
    if (curr == n - 1) {
      if (total == 0) break;
      sum -= (*s.begin()).first;
      s.erase(*s.begin());
      ans += sum;
      c++;
      total--;
    }
    if (total == 0) {
      sum = 0;
      curr++;
      if (curr == n) break;
      s.insert(make_pair(v[curr].second, curr));
      sum = v[curr].second;
      total++;
      while (curr < n - 1 && v[curr].first == v[curr + 1].first) {
        s.insert(make_pair(v[curr + 1].second, curr + 1));
        curr++;
        sum += v[curr].second;
        total++;
      }
      c = v[curr].first + 1;
      sum -= (*s.begin()).first;
      ans += sum;
      s.erase(*s.begin());
      total--;
      continue;
    }
    if (curr + 1 < n && c == v[curr + 1].first) {
      curr++;
      if (curr == n) break;
      s.insert(make_pair(v[curr].second, curr));
      sum += v[curr].second;
      total++;
      while (curr < n - 1 && v[curr].first == v[curr + 1].first) {
        s.insert(make_pair(v[curr + 1].second, curr + 1));
        curr++;
        sum += v[curr].second;
        total++;
      }
      c = v[curr].first + 1;
      sum -= (*s.begin()).first;
      ans += sum;
      s.erase(*s.begin());
      total--;
      continue;
    }
    sum -= (*s.begin()).first;
    s.erase(*s.begin());
    ans += sum;
    c++;
    total--;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t = 1, tt = 1;
  while (tt <= t) {
    solve();
    tt++;
  }
}
