#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> arr[200100];
vector<long long> barr;
multiset<pair<long long, long long> > st;
int main() {
  long long t, n, i, j, K, k, l, m;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  t = 1;
  while (t--) {
    cin >> n;
    for (i = 0; i < n; i++) cin >> arr[i].first;
    for (i = 0; i < n; i++) cin >> arr[i].second;
    sort(arr, arr + n);
    int maxi = -1;
    for (i = 0; i < n; i++) {
      if (maxi < arr[i].first)
        maxi = arr[i].first;
      else
        maxi++;
      barr.push_back(maxi);
    }
    j = 0;
    long long ans = 0;
    for (i = 0; i < n; i++) {
      while (j < n && arr[j].first <= barr[i]) {
        st.insert(pair<long long, long long>(-arr[j].second, arr[j].first));
        j++;
      }
      pair<long long, long long> op = *(st.begin());
      st.erase(st.begin());
      ans += (barr[i] - op.second) * (-op.first);
    }
    cout << ans << '\n';
  }
  return 0;
}
