#include <bits/stdc++.h>
using namespace std;
struct Element {
  int value, cost;
  inline bool operator<(const Element &x) const { return value < x.value; }
};
Element a[200005];
priority_queue<int> heap;
int n, pnt, now, tmp;
long long ans, nowans;
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; i++) {
    scanf("%d", &a[i].value);
  }
  for (register int i = 1; i <= n; i++) {
    scanf("%d", &a[i].cost);
  }
  sort(a + 1, a + n + 1);
  while (pnt < n || heap.empty() == false) {
    tmp++;
    if (heap.empty() == true) {
      tmp = a[pnt + 1].value;
    }
    while (pnt < n && a[pnt + 1].value == tmp) {
      pnt++;
      nowans += a[pnt].cost;
      heap.push(a[pnt].cost);
    }
    nowans -= heap.top();
    heap.pop();
    ans += nowans;
  }
  printf("%lld\n", ans);
  return 0;
}
