#include <bits/stdc++.h>
typedef struct some {
  int time, num;
} node;
int heap[200001], heapcap;
node book[200001];
int cmpfunc(const void* a, const void* b) {
  node *p = (node*)a, *q = (node*)b;
  if (p->num != q->num)
    return p->num - q->num;
  else
    return p->time - q->time;
}
void swap(int* a, int* b) {
  int temp = *a;
  *a = *b;
  *b = temp;
}
void add(int x) {
  heap[++heapcap] = x;
  int pos = heapcap;
  while (pos > 1 && heap[pos] > heap[pos / 2]) {
    swap(&heap[pos], &heap[pos / 2]);
    pos /= 2;
  }
}
int pop(void) {
  swap(&heap[1], &heap[heapcap--]);
  int pos = 1;
  while (1 + 2 * pos <= heapcap &&
         (heap[pos * 2] > heap[pos] || heap[pos * 2 + 1] > heap[pos])) {
    int temp = heap[pos * 2] > heap[pos * 2 + 1] ? pos * 2 : pos * 2 + 1;
    swap(&heap[pos], &heap[temp]);
    pos = temp;
  }
  if (pos * 2 == heapcap && heap[pos * 2] > heap[pos])
    swap(&heap[pos], &heap[pos * 2]);
  return heap[heapcap + 1];
}
int main(void) {
  int i, n, cur = 0;
  long long int ans = 0, temp = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &book[i].num);
  for (i = 1; i <= n; i++) scanf("%d", &book[i].time);
  qsort(&book[1], n, sizeof(node), cmpfunc);
  i = 1;
  while (heapcap || i <= n) {
    if (!heapcap) cur = book[i].num;
    while (i <= n && cur == book[i].num) {
      add(book[i].time);
      temp += book[i].time;
      i++;
    }
    temp -= pop();
    ans += temp;
    cur++;
  }
  printf("%I64d", ans);
}
