#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
priority_queue<int> pq;
pair<int, int> a[N];
long long ans, sum;
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i].first;
  for (int i = 1; i <= n; ++i) cin >> a[i].second;
  sort(a + 1, a + n + 1);
  int i = 1, curr = 0;
  while (!pq.empty() || i <= n) {
    if (pq.empty()) curr = a[i].first;
    for (; i <= n && a[i].first == curr; ++i) {
      pq.push(a[i].second);
      sum += a[i].second;
    }
    sum -= pq.top();
    pq.pop();
    ans += sum;
    ++curr;
  }
  cout << ans;
}
