#include <bits/stdc++.h>
using namespace std;
struct node {
  long long x, t;
  bool operator<(const node &f) const { return t > f.t; }
} a[200005];
bool cmp(node x, node y) {
  if (x.x == y.x) return x.t > y.t;
  return x.x < y.x;
}
map<long long, int> m;
map<long long, long long> f;
map<long long, long long> cnt;
int main() {
  long long n;
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i].x);
    cnt[a[i].x]++;
    m[a[i].x]++;
  }
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i].t);
  long long ans = 0;
  sort(a + 1, a + 1 + n, cmp);
  priority_queue<long long> q;
  for (int i = 1; i <= n; i++) {
    long long sum = 0;
    sum += a[i].t;
    int j = i;
    long long now = a[i].x;
    q.push(a[i].t);
    while (!q.empty()) {
      while (a[i + 1].x == now && i + 1 <= n) {
        sum += a[i + 1].t;
        i++;
        q.push(a[i].t);
      }
      long long k = q.top();
      q.pop();
      ans += sum - k;
      sum -= k;
      now++;
    }
  }
  printf("%lld\n", ans);
}
