#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int MAX = 1000;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, m;
struct re {
  int a, t;
} a[maxn];
priority_queue<int> q;
bool cmp(re a, re b) {
  if (a.a == b.a) return a.t < b.t;
  return a.a < b.a;
}
signed main() {
  int n;
  cin >> n;
  for (int i = (1); i <= (n); ++i) {
    scanf("%d", &a[i].a);
  }
  for (int i = (1); i <= (n); ++i) {
    scanf("%d", &a[i].t);
  }
  sort(a + 1, a + 1 + n, cmp);
  long long ans = 0;
  long long sum;
  int lay = 0;
  a[n + 1].a = 2e9;
  for (int i = (1); i <= (n + 1); ++i) {
    while (a[i].a > lay) {
      if (q.size() <= 1) {
        while (!q.empty()) q.pop();
        sum = 0;
        lay = a[i].a;
        break;
      }
      lay++;
      sum -= 1ll * q.top();
      ans += sum;
      q.pop();
    }
    q.push(a[i].t);
    sum += a[i].t;
  }
  cout << (ans) << endl;
}
