#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long int gcd, masks, mask, i, h, n, d, l, r, j, k, x, y, z, x1, y1, p,
      x2, y2, m, root, t, sum, size, ind;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  vector<pair<long long int, long long int> > vp;
  for (i = 0; i < n; i++) {
    vp.push_back({a[i], b[i]});
  }
  sort(vp.begin(), vp.end());
  priority_queue<pair<long long int, long long int> > pq;
  x = vp[0].first;
  i = 0;
  long long int ans = 0;
  while (i < n || pq.size() != 0) {
    while (i < n && x == vp[i].first) {
      pq.push({vp[i].second, vp[i].first});
      i++;
    }
    ans += ((x - pq.top().second) * pq.top().first);
    pq.pop();
    if (i != n && pq.size() == 0)
      x = vp[i].first;
    else
      x++;
  }
  cout << ans;
  return 0;
}
