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

///#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,avx,sse4.1,sse4.2,mmx")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define ff first
#define ss second
#define db double
#define auf true
#define pb push_back
#define what(x) cerr << #x << " = " << x << '\n'

const int N = 1e6 + 5, M = 3e3 + 5;
const int inf = 1e18 + 100, mod = 1e9 + 7;
const db eps = 1e-9;

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

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
    return mt_rnd_64() % (r - l + 1) + l;
}

pair < int, int > p[N];

ordered_set s;

signed main()
{
//  #ifndef _WIN32
//    freopen("lz.in", "r", stdin);
//    freopen("lz.out", "w", stdout);
//  #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> p[i].ff;
    for (int i = 1; i <= n; ++i)
        cin >> p[i].ss;

    sort(p + 1, p + n + 1);
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cnt = s.order_of_key({p[i].ss, 0});
        ans += cnt * p[i].ff;
        s.insert({p[i].ss, i});
    }

    s.clear();

    for (int i = n; i >= 1; --i)
    {
        int cnt = (int)s.size() - s.order_of_key({p[i].ss - 1, n + 1});
        ans -= cnt * p[i].ff;
        s.insert({p[i].ss, i});
    }

    cout << ans;
    return 0;
}
/// hto ya? zvychayna domohospodarka chy president Ykrainy?
/// ���)
