#include <bits/stdc++.h>
using namespace std;
struct Obj {
  int val, time;
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  vector<Obj> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].val;
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i].time;
  }
  sort(a.begin(), a.end(), [](const Obj &left, const Obj &right) {
    if (left.val == right.val) {
      return left.time < right.time;
    }
    return left.val < right.val;
  });
  priority_queue<pair<int, int> > pq;
  int next;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    next = (i == n - 1 ? INT_MAX : a[i + 1].val);
    pq.push({a[i].time, a[i].val});
    int j = a[i].val;
    while (!pq.empty() && j < next) {
      auto cur = pq.top();
      pq.pop();
      ans += 1LL * cur.first * (j - cur.second);
      j++;
    }
  }
  cout << ans;
  return 0;
}
