#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > adj(1000005);
long long int vis[1000005];
vector<bool> prime(1000005, true);
void pre() {
  for (int i = 2; i * i < 1000005; i++) {
    if (prime[i] == false) continue;
    for (int j = 2 * i; j < 1000005; j += i) {
      prime[j] = false;
    }
  }
}
struct comp {
  bool operator()(pair<long long int, long long int> p1,
                  pair<long long int, long long int> p2) {
    if (p1.second == p2.second) return p1.first > p2.first;
    return p1.second < p2.second;
  }
};
long long int mini = 1e18, cnt = 0;
map<pair<long long int, long long int>, long long int> dir;
vector<long long int> c(300005, 0);
void dfs(long long int v) {
  vis[v] = 1;
  for (auto x : adj[v]) {
    if (!vis[x]) {
      dfs(x);
      c[v] += c[x];
    }
  }
  c[v]++;
}
vector<pair<long long int, long long int> > ans;
void dfs2(long long int v, long long int n) {
  vis[v] = 1;
  for (auto x : adj[v]) {
    if (!vis[x]) {
      if (2 * c[x] == n) {
        long long int d = adj[x][0];
        if (d == v) {
          d = adj[x][1];
        }
        ans.push_back({x, d});
        ans.push_back({v, d});
        return;
      }
      dfs2(x, n);
    }
  }
}
int p2[300005];
long long int mod = 1000000007;
long long int power(long long int x, long long int y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return ((power(x, y / 2)) % mod * (power(x, y / 2)) % mod) % mod;
  else
    return (x % mod * (power(x, y / 2)) % mod * (power(x, y / 2)) % mod) % mod;
}
long long int check(long long int tot, long long int n, long long int gp,
                    long long int m) {
  long long int q = n / gp, r = n % gp;
  long long int sub =
      ((r * (q * (q + 1))) / 2) + (((gp - r) * (q * (q - 1))) / 2);
  return tot - sub >= m;
}
long long int check(long long int n) { return ((n * (n + 1) * (n + 2)) / 6); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int q = 1;
  while (q--) {
    long long int n, i, j, ans = 0;
    cin >> n;
    pair<long long int, long long int> p[n];
    long long int a[n];
    for (i = 0; i < n; i++) {
      cin >> p[i].first;
      a[i] = p[i].first;
    }
    for (i = 0; i < n; i++) {
      cin >> p[i].second;
    }
    sort(p, p + n);
    sort(a, a + n);
    for (i = 1; i <= n; i++) {
      p[i].first = max(p[i - 1].first + 1, p[i].first);
    }
    long long int in = 0;
    priority_queue<pair<long long int, long long int> > pq;
    for (long long int j = 0; j < n; j++) {
      while (in < n && a[in] <= p[j].first) {
        pq.push({p[in].second, a[in]});
        in++;
      }
      pair<long long int, long long int> maxi = pq.top();
      pq.pop();
      ans += ((p[j].first - maxi.second) * maxi.first);
    }
    cout << ans << endl;
  }
}
