#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
const long long mod = 1e9 + 7;
void unify(vector<long long>& v) {
  auto ip = unique(v.begin(), v.end());
  v.resize(distance(v.begin(), ip));
}
long long gcd(long long int x, long long int y) {
  return y == 0 ? x : gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x * y / gcd(x, y); }
bool isPower2(long long x) { return x && (!(x & (x - 1))); }
const int N = 998244353;
void solve() {
  int n;
  cin >> n;
  long long ans = 0;
  vector<pair<long long, long long>> v(n);
  priority_queue<long long> q;
  for (int i = 0; i < n; i++) cin >> v[i].first;
  for (int i = 0; i < n; i++) cin >> v[i].second;
  sort(v.begin(), v.end());
  int j = 0;
  for (int i = 0; i < n; i++) {
  }
  long long cur_sum = 0;
  for (int i = 0; i < n; i = j) {
    while (j < n && v[j].first == v[i].first) {
      q.push(v[j].second);
      cur_sum += v[j].second;
      j++;
    }
    cur_sum -= q.top();
    q.pop();
    ans += cur_sum;
    if (!q.size()) continue;
    if (j == n) {
      cur_sum -= q.top();
      q.pop();
      while (q.size()) {
        ans += cur_sum;
        cur_sum -= q.top();
        q.pop();
      }
      break;
    }
    long long cur = v[i].first + 1;
    if (cur < v[j].first) {
      cur_sum -= q.top();
      q.pop();
      while (cur != v[j].first && q.size()) {
        ans += cur_sum;
        cur++;
        if (cur == v[j].first) break;
        cur_sum -= q.top();
        q.pop();
      }
    }
  }
  cout << ans << endl;
}
int main() {
  int t = 1;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  while (t--) {
    solve();
  }
  return 0;
}
