#include <bits/stdc++.h>
using namespace std;

void executeTime() {
    cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " secs";
}

using ll = long long;

int main() {

    int n; cin >> n;

    vector<array<int, 2>> v(n);
    for (auto &x : v) {
        cin >> x[0];
    }

    for (auto &x : v) {
        cin >> x[1];
    }

    sort(v.begin(), v.end());

    priority_queue<array<int, 2>> pq;

    ll sum = 0, ans = 0;

    int curr = v[0][0];

    int i = 0;

    while (i < n) {

        while (i < n && v[i][0] == curr) {
            pq.push({v[i][1], v[i][0]});
            sum += v[i][1];
            i++;
        }

        if (pq.empty()) {
            curr = v[i][0];
            continue;
        }

        int c = pq.top()[0];
        pq.pop();

        sum -= c;
        ans += sum;
        curr++;
    }

    while (!pq.empty()) {
        int c = pq.top()[0];
        sum -= c;

        pq.pop();

        ans += sum;
    }

    cout << ans << endl;

    executeTime();
    return 0;
}