#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
const long long N = 2e5 + 7;
const int mod = 998244353;
const long long inf = 8e18 + 7;
long long n, a[N];
struct node {
  long long val, t;
  bool operator<(const node& a) const {
    return t == a.t ? val > a.val : t < a.t;
  }
};
int main() {
  cin >> n;
  priority_queue<node> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1, x = 1; i <= n; i++) cin >> x, q.push({a[i], x});
  long long ans = 0;
  unordered_set<long long> et;
  unordered_map<long long, long long> mp;
  while (!q.empty()) {
    long long val = q.top().val;
    long long t = q.top().t;
    long long pos = val, tmp = pos;
    q.pop();
    while (et.count(val)) val = mp[val];
    while (et.count(tmp)) {
      long long k = tmp;
      tmp = mp[tmp];
      mp[k] = val + 1;
    }
    et.insert(val);
    mp[val] = val + 1;
    ans += (val - pos) * t;
  }
  cout << ans << "\n";
  return 0;
}
