#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const long long mod = 1e9 + 7;
map<long long, long long> m;
vector<pair<long long, long long> > num;
long long find(long long x) {
  if (m[x] == 0) return x;
  return m[x] = find(m[x]);
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  return a > b;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    pair<long long, long long> p;
    cin >> p.second;
    num.push_back(p);
  }
  for (pair<long long, long long> &p : num) {
    cin >> p.first;
  }
  sort(num.begin(), num.end(), cmp);
  long long ans = 0;
  for (pair<long long, long long> p : num) {
    long long x = find(p.second);
    m[x] = x + 1;
    ans += (x - p.second) * p.first;
  }
  cout << ans << '\n';
  return 0;
}
