/*
File created on 08/05/2021 at 18:39:44.
Link to problem: 
Description: 
Time complexity: O()
Space complexity: O()
Status: DEV (most of the time I don't update status, so it stays DEV which is the default value)
Copyright: Ⓒ 2021 Francois Vogel
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

#define pii pair<int, int>
#define f first
#define s second

#define vi vector<int>
#define all(x) x.begin(), x.end()
#define size(x) (int)(x.size())
#define pb push_back
#define ins insert
#define cls clear

#define ll long long
#define ld long double

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int p2 = 1<<20;

int bt [p2*2];
int get(int b, int e) {
    b += p2;
    e += p2;
    int sum = 0;
    while (b <= e) {
        if (b%2 == 1) sum = bt[b++];
        if (e%2 == 0) sum += bt[e--];
        b /= 2;
        e /= 2;
    }
    return sum;
}

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    vector<pii> b(n);
    for (int i = 0; i < n; i++) cin >> b[i].s;
    for (int i = 0; i < n; i++) cin >> b[i].f;
    set<int> allS;
    for (int i = 0; i < n; i++) allS.ins(b[i].s);
    unordered_map<int, int> compress;
    int k = 0;
    for (int i : allS) compress[i] = k++;
    sort(all(b));
    for (int i = 0; i < p2*2; i++) bt[i] = 0;
    int sum = 0;
    ordered_set os;
    for (pii i : b) {
        sum += os.order_of_key(i.s+1)*i.s;
        os.ins(i.s);
        sum -= get(0, compress[i.s]);
        for (int j = compress[i.s]+p2; j; j /= 2) bt[j] += i.s;
    }
    cout << sum;

    int d = 0;
    d++;
}