#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
struct cat {
  long long a;
  int t;
  cat() : a(0), t(0) {}
};
bool comp(cat c1, cat c2) { return c1.a < c2.a; }
int main() {
  int N;
  cin >> N;
  vector<cat> C(N);
  for (int i = (int)(0); i < (int)(N); i++) cin >> C[i].a;
  for (int i = (int)(0); i < (int)(N); i++) cin >> C[i].t;
  sort(C.begin(), C.end(), comp);
  priority_queue<int> q;
  int i = 0;
  long long ans = 0;
  long long sum = 0;
  int prev = 0;
  while (i < N) {
    int tmp = C[i].a;
    while (C[i].a == tmp) {
      q.push(C[i].t);
      sum += C[i].t;
      i++;
    }
    while (!q.empty() && i < N && tmp < C[i].a) {
      int top = q.top();
      sum -= top;
      q.pop();
      ans += sum;
      tmp++;
    }
  }
  while (!q.empty()) {
    int top = q.top();
    sum -= top;
    q.pop();
    ans += sum;
  }
  cout << ans << endl;
  return 0;
}
