#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  priority_queue<pair<int, int> > pq;
  int n;
  cin >> n;
  vector<pair<int, int> > v(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v[i].first = x;
  }
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    v[i].second = t;
  }
  sort(v.begin(), v.end());
  int prev = v[0].first;
  pq.push({v[0].second, v[0].first});
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    int cur = v[i].first;
    while (prev < cur && !pq.empty()) {
      pair<int, int> p = pq.top();
      ans += 1LL * (prev - p.second) * p.first;
      pq.pop();
      ++prev;
    }
    pq.push({v[i].second, v[i].first});
    prev = cur;
  }
  while (!pq.empty()) {
    pair<int, int> p = pq.top();
    ans += 1LL * (prev - p.second) * p.first;
    pq.pop();
    ++prev;
  }
  cout << ans;
  return 0;
}
