#include <bits/stdc++.h>
using namespace std;
const int N = 200009;
pair<int, int> a[N];
priority_queue<int> f;
int main(void) {
  int n;
  int i, j, k;
  long long o, s;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i].first);
  for (i = 0; i < n; i++) scanf("%d", &a[i].second);
  a[n].first = 2000000000;
  sort(a, a + n);
  for (i = o = s = 0; i < n; i = j) {
    for (j = i; j < n && a[j].first == a[i].first; j++) {
      s += a[j].second;
      f.push(a[j].second);
    }
    for (k = 0; k < a[j].first - a[i].first && !f.empty(); k++) {
      s -= f.top();
      o += s;
      f.pop();
    }
  }
  cout << o << "\n";
  return 0;
}
