#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <iterator>
#include <map>
#include <functional>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <unordered_map>
#include <numeric>

#define ll long long
#define ld long double
#define y1 abc
#define endl '\n'
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000
#define MINLL -9000000000000000000LL
#define MININT -2000000000
#define stoi aaaaavasd
#define pll pair < ll, ll >

using namespace std;
using namespace __gnu_pbds;

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

const ld pi = acos(-1);
const ll md = 1e9 + 7;

ll n, a[200501], vel[200501], i, r, sm, ans, fen[200501], fen2[200501];

vector < pll > v1, v2;

bool cmp(pll a, pll b)
{
    if (a.se == b.se) return a.fi < a.se;
    else return abs(a.se) < abs(b.se);
}

bool cmp1(pll a, pll b)
{
    if (a.se == b.se) return a.fi > a.se;
    else return abs(a.se) < abs(b.se);
}

void update(ll x, ll y)
{
    for (; x < v1.size(); x |= x + 1) fen[x] += y;
}

ll get(ll x)
{
    ll res = 0;

    for (; x >= 0; x = (x & (x + 1)) - 1) res += fen[x];

    return res;
}

void update2(ll x, ll y)
{
    for (; x < v1.size(); x |= x + 1) fen2[x] += y;
}

ll get2(ll x)
{
    ll res = 0;

    for (; x >= 0; x = (x & (x + 1)) - 1) res += fen2[x];

    return res;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;

    for (i = 1; i <= n; i++){
        cin >> a[i];
    }

    for (i = 1; i <= n; i++){
        cin >> vel[i];

        if (vel[i] == 0){
            v1.pb({a[i], vel[i]});
            v2.pb({a[i], vel[i]});
        }
        else if (vel[i] < 0) v1.pb({a[i], vel[i]});
        else v2.pb({a[i], vel[i]});
    }

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    for (i = 0; i < v2.size(); i++){
        while (r < v1.size() && v1[r].fi <= v2[i].fi){
            sm += v1[r].fi;
            r++;
        }

        ans += v2[i].fi * r - sm;
    }

    v1.clear();

    for (i = 1; i <= n; i++) if (vel[i] < 0) v1.pb({a[i], vel[i]});

    sort(v1.begin(), v1.end(), cmp1);
    v2.clear();

    for (i = 0; i < v1.size(); i++){
        v2.pb({v1[i].fi, i});
        update(i, v1[i].fi);
    }

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

    sm = 0;

    for (i = 0; i < v2.size(); i++){
        ans += v2[i].fi * i - sm;
        sm += v2[i].fi;
    }

    for (i = 0; i < v1.size(); i++) update2(i, 1);

    for (i = 0; i < v1.size(); i++){
        pll x = v2.back();
        v2.pop_back();

        ans -= get2(x.se - 1) * x.fi - get(x.se - 1);
        update(x.se, 0 - x.fi);
        update2(x.se, -1);
    }

    v1.clear();
    v2.clear();

    for (i = 1; i <= n; i++){
        if (vel[i] > 0) v1.pb({a[i], vel[i]});
    }

    sort(v1.begin(), v1.end(), cmp);

    for (i = 0; i < v1.size(); i++){
        v2.pb({v1[i].fi, i});
        update(i, v1[i].fi);
    }

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

    sm = 0;

    for (i = 0; i < v2.size(); i++){
        ans += v2[i].fi * i - sm;
        sm += v2[i].fi;
    }

    reverse(v2.begin(), v2.end());

    for (i = 0; i < v1.size(); i++) update2(i, 1);

    for (i = 0; i < v1.size(); i++){
        pll x = v2.back();
        v2.pop_back();
 
        ans -= get(x.se - 1) - get2(x.se - 1) * x.fi;
        update(x.se, 0 - x.fi);
        update2(x.se, -1);
    }

    cout << ans << endl;

    return 0;
}