#include <bits/stdc++.h>
using namespace std;
long long int expo(long long int n) {
  long long int t;
  if (n == 0)
    return 1;
  else if (n == 1)
    return 2;
  t = expo(n / 2);
  if (n % 2) {
    return t * t * 2;
  } else
    return t * t;
}
long long int exponentMod(long long int A, long long int B, long long int C) {
  if (A == 0) return 0;
  if (B == 0) return 1;
  long long int y;
  if (B % 2 == 0) {
    y = exponentMod(A, B / 2, C);
    y = (y * y) % C;
  } else {
    y = A % C;
    y = (y * exponentMod(A, B - 1, C) % C) % C;
  }
  return (long long int)((y + C) % C);
}
int main() {
  long long int n;
  cin >> n;
  pair<long long int, long long int> p[n + 1];
  for (int i = 0; i < n; i++) cin >> p[i].first;
  for (int i = 0; i < n; i++) cin >> p[i].second;
  sort(p, p + n);
  priority_queue<long long int> m;
  long long int i = 0;
  long long int cur = p[i].first;
  long long int sum = 0, ans = 0;
  while (i < n || m.size()) {
    if (m.size() == 0) cur = p[i].first;
    while (i < n && cur == p[i].first) {
      m.push(p[i].second);
      sum += p[i].second;
      i++;
    }
    sum -= m.top();
    m.pop();
    ans += sum;
    cur++;
  }
  cout << ans << "\n";
}
