#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define N 1000005
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
struct FenwickTree {
    vector<int> bit;  // binary indexed tree
    int n;
    vector<int> cnt;
    FenwickTree(int n) {
        this->n = n;
        bit.assign(n, 0);
        cnt.assign(n,0);
    }

    FenwickTree(vector<int> a) : FenwickTree(a.size()) {
        for (size_t i = 0; i < a.size(); i++)
            add(i, a[i]);
    }

    pair<int,int> sum(int r) {
        int ret = 0;
        int t = r;
        for (; r >= 0; r = (r & (r + 1)) - 1)
            ret += bit[r];
        int ret2 = 0;
        r = t;
        for (; r >= 0; r = (r & (r + 1)) - 1)
            ret2 += cnt[r];
        return {ret,ret2};
    }

    pair<int,int> sum(int l, int r) {
        auto j = sum(r);
        auto j2 = sum(l-1);
        return {j.fr-j2.fr, j.sc-j2.sc};
    }

    void add(int idx, int delta) {
        int t = idx;
        for (; idx < n; idx = idx | (idx + 1))
            bit[idx] += delta;
        idx = t;
        for (; idx < n; idx = idx | (idx + 1))
            cnt[idx] += 1;
    }
};
FenwickTree ft(1000005);
map<int,int> compress, decompress;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree < int, null_type, less_equal<int>,rb_tree_tag,tree_order_statistics_node_update >
signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n;
        cin >> n;
        int x[n];
        rep(i,0,n) cin >> x[i];
        int v[n];
        rep(i,0,n) cin >> v[i];
        set<int> vv;
        rep(i,0,n) vv.insert(abs(v[i]));
        int i = 0;
        for(auto j:vv){
            if(j==0) compress[j] = 0;
            else compress[j] = i+1;
            i++;
        }
        rep(i,0,n){
            if(v[i]>=0) v[i] = compress[v[i]];
            else v[i] = -compress[-v[i]];
        }
        int left = 0, right = 0;
        int cntl=0, cntr = 0;
        int ans = 0;
        rep(i,0,n){
            if(v[i]>0){
                ans += x[i]*cntl-left;
            }
            else if(v[i]<0){
                cntl++;
                left+= x[i];
            }   
        }
        vector<pair<int,int>> ve;
        rep(i,0,n) ve.pb({x[i],v[i]});
        sort(all(ve));
        rep(i,0,n){
            x[i]=ve[i].fr;
            v[i]=ve[i].sc;
        }
        // trace(ans);
        rep(i,0,n){
            if(v[i]>0){
                ans += ft.sum(0,v[i]).sc*x[i]-ft.sum(0,v[i]).fr;
                ft.add(v[i],x[i]);
                // trace(ans);
            }
        }
        rep(i,0,1000005){
            ft.bit[i] = 0;
            ft.cnt[i] = 0;
        }
        rep(i,0,n){
            if(v[i]<0){
                v[i] = -v[i];
                ans += ft.sum(v[i],1000000).sc*x[i]-ft.sum(v[i],1000000).fr;
                ft.add(v[i],x[i]);
            }
        }
        int sum = 0;
        int cnt = 0;
        rep(i,0,n){
            if(v[i]==0){
                ans += cnt*x[i]-sum;
                sum += x[i];
                cnt++;
            }
        }
        cout << ans;
    }
}