#include <bits/stdc++.h>
using namespace std;
int n, i, j = 1;
pair<int, int> c[200000];
priority_queue<int> q;
long long s, ans;
inline void init_j() {
  if (q.empty()) j = c[i].first;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> c[i].first;
  for (int i = 0; i < n; ++i) cin >> c[i].second;
  for (sort(c, c + n); !q.empty() || i < n;
       j++, s -= q.top(), ans += s, q.pop())
    for (init_j(); i < n && c[i].first == j; i++)
      q.push(c[i].second), s += c[i].second;
  cout << ans;
}
