#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
  }
  sort(a.begin(), a.end());
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    s[i] = a[i].first;
    if (i != 0) {
      s[i] = max(s[i], s[i - 1] + 1);
    }
  }
  sort(a.begin(), a.end(), [](pair<int, int> x, pair<int, int> y) {
    if (x.second == y.second) {
      return x.first < y.first;
    }
    return x.second < y.second;
  });
  multiset<int> t;
  for (auto to : s) t.insert(to);
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    auto it = t.lower_bound(a[i].first);
    ans += (*it - a[i].first) * (long long)a[i].second;
    t.erase(it);
  }
  cout << ans << '\n';
  return 0;
}
