#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base ::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<long long, long long>> news(n + 1);
  for (int i = 1; i <= n; i++) cin >> news[i].first;
  for (int i = 1; i <= n; i++) cin >> news[i].second;
  long long ans = 0;
  priority_queue<long long> q;
  sort(news.begin() + 1, news.end());
  long long val = news[1].first, sum = 0;
  news.push_back(make_pair(2e9, 0));
  for (int i = 1; i <= n + 1; i++) {
    while (val < news[i].first && q.size() > 0) {
      sum -= q.top();
      q.pop();
      ans += sum;
      val++;
    }
    val = news[i].first;
    q.push(news[i].second);
    sum += news[i].second;
  }
  cout << ans;
}
