#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
struct node {
  long long x, p;
} a[maxn << 1];
bool cmp(node a, node b) {
  if (a.p == b.p)
    return a.x < b.x;
  else
    return a.p > b.p;
}
map<long long, long long> f;
long long Find(long long x) { return f[x] == 0 ? x : f[x] = Find(f[x]); }
void Union(long long x, long long y) {
  x = Find(x), y = Find(y);
  if (x != y) f[x] = y;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i].x;
  for (int i = 1; i <= n; i++) cin >> a[i].p;
  sort(a + 1, a + n + 1, cmp);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long tmp = Find(a[i].x);
    ans += (tmp - a[i].x) * a[i].p;
    Union(tmp, tmp + 1);
  }
  cout << ans << endl;
}
