#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * neg;
}
inline void print(long long x) {
  if (x < 0) {
    putchar('-');
    print(abs(x));
    return;
  }
  if (x <= 9)
    putchar(x + '0');
  else {
    print(x / 10);
    putchar(x % 10 + '0');
  }
}
inline long long qpow(long long x, long long e, long long _MOD) {
  long long ans = 1;
  while (e) {
    if (e & 1) ans = ans * x % _MOD;
    x = x * x % _MOD;
    e >>= 1;
  }
  return ans;
}
long long n = read();
pair<long long, long long> a[200005];
map<long long, long long> cnt;
long long l[200005], r[200005], num = 0;
signed main() {
  for (long long i = 1; i <= n; i++) a[i].first = read(), cnt[a[i].first]++;
  for (long long i = 1; i <= n; i++) a[i].second = read();
  sort(a + 1, a + n + 1);
  for (long long i = 1; i <= n;) {
    long long sum = 0;
    long long cur = i;
    while (cur <= n) {
      sum++;
      if (cur == n) break;
      if (a[cur + 1].first > (a[i].first + sum - 1)) break;
      cur++;
    }
    l[++num] = i;
    r[num] = cur;
    i = cur + 1;
  }
  long long ans = 0;
  for (long long i = 1; i <= num; i++) {
    for (long long j = l[i]; j <= r[i]; j++) ans -= a[j].first * a[j].second;
    map<long long, bool> used;
    long long _l = a[l[i]].first, _r = _l + r[i] - l[i], cur = l[i];
    priority_queue<long long> pq;
    for (long long j = _l; j <= _r; j++) {
      while (a[cur].first <= j && cur <= r[i]) {
        pq.push(a[cur].second);
        cur++;
      }
      ans += j * pq.top();
      pq.pop();
    }
  }
  print(ans);
  putchar('\n');
  return 0;
}
