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

using namespace std;
using namespace __gnu_pbds;
using namespace std::chrono;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
///find_by_order, order_of_key

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void update(vector<ll> &bit, ll index, ll delta)
{
    ++index;
    for(; index < bit.size(); index += index&-index)
    {
        bit[index-1] += (ll)delta;
    }
}

ll sum(vector<ll> &bit, ll index)
{
    ll suma = 0LL;
    ++index;
    for(; index >= 1; index -= index&-index)
    {
        suma += bit[index-1];
    }
    return suma;
}

int main()
{
    #ifdef ljuba
    auto pocetakChronoSata123 = high_resolution_clock::now();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);       
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;

    vector<pii> p(n);
    for(auto &z : p)
        cin >> z.fi;
    for(auto &z : p)
        cin >> z.se;
    sort(all(p));

    vi brzine;

    for(int i = 0; i < n; ++i)
        brzine.pb(p[i].se);
    sort(all(brzine));
    brzine.resize(unique(all(brzine)) - brzine.begin());

    ll res = 0;

    vector<ll> cnt(brzine.size()), manjeBrzine(brzine.size());
    for(auto &pnt : p)
    {
        int index = lower_bound(all(brzine), pnt.se) - brzine.begin();
        res += sum(cnt, index) * 1LL * (ll)pnt.fi - sum(manjeBrzine, index);
        update(cnt, index, 1);
        update(manjeBrzine, index, pnt.fi);
    }

    cout << res << '\n';

    #ifdef ljuba
    auto krajChronoSata123 = high_resolution_clock::now();
    auto trajanje = duration_cast<microseconds>(krajChronoSata123 - pocetakChronoSata123);
    cout << "----------------------------------------------------\n";
    cout << "Vreme u milisekundama: " << (ld)trajanje.count() / 1000.00 << '\n';
    #endif
    return 0;
}