#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 2e5;
struct mode {
  int a, t;
} b[N + 5];
int n;
map<int, int> mp;
long long ans;
int find(int x, long long pay) {
  if (mp[x]) {
    ans += (mp[x] - x) * pay;
    return mp[x] = find(mp[x], pay);
  } else {
    mp[x] = x + 1;
    return x + 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i].a;
  for (int i = 1; i <= n; i++) cin >> b[i].t;
  sort(b + 1, b + 1 + n,
       [](const mode &m1, const mode &m2) -> bool { return m1.t > m2.t; });
  for (int i = 1; i <= n; i++) {
    if (!mp[b[i].a])
      mp[b[i].a] = b[i].a + 1;
    else
      find(b[i].a, b[i].t);
  }
  cout << ans << endl;
  return 0;
}
