#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > v;
long long A[1000006], cost[1000006], res;
map<long long, long long> par;
long long rep(long long x) {
  if (!par[x]) return par[x] = x;
  if (par[x] == x) return x;
  return par[x] = rep(par[x]);
}
void join(long long x, long long y) {
  long long a = rep(x);
  long long b = rep(y);
  if (a != b) {
    par[b] = a;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    par[A[i]] = A[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> cost[i];
  }
  for (int i = 1; i <= n; i++) {
    v.push_back({-cost[i], A[i]});
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    long long x = v[i].second;
    res += (rep(x) - x) * -v[i].first;
    join(rep(rep(x) + 1), rep(x));
  }
  cout << res << endl;
  return 0;
}
