#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n;
pair<int, int> data[MAXN];
long long ans;
priority_queue<int> line;
long long cnt;
int niz;
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) scanf("%d", &data[i].first);
  for (register int i = 1; i <= n; ++i) scanf("%d", &data[i].second);
  sort(data + 1, data + 1 + n);
  for (register int i = 1; i <= n;) {
    niz = niz ? niz : data[i].first;
    while (i <= n && data[i].first == niz) {
      line.push(data[i].second);
      cnt += data[i].second;
      i++;
    }
    if (line.size() == 1) {
      niz = 0;
      cnt -= line.top();
      line.pop();
    } else {
      ans += cnt - (long long)line.top();
      cnt -= line.top();
      line.pop();
      niz++;
    }
  }
  while (line.size() >= 2) {
    ans += cnt - (long long)line.top();
    cnt -= line.top();
    line.pop();
  }
  printf("%lld\n", ans);
  return 0;
}
