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


typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;


#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=2e5+5, mxN=(1<<20)+5;
int mod=998244353 ;

ll mul(ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll add(ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a+b+mod)%mod;
}
ll fastpow(ll b, ll p)
{
    if(p==0)
        return 1;
    ll ans=fastpow(b,p/2);
    ans=mul(ans,ans);
    if(p%2)
        ans=mul(ans,b);
    return ans;
}
ll fac(ll n)
{
    ll ans=1;
    while(n)
    {
        ans=mul(ans,n--);
    }
    return  ans;
}
ll ncr(ll n, ll r)
{
    ll ans=fac(n);
    ll m=mul(fac(r),fac(n-r));
    ans=mul(ans,fastpow(m,mod-2));
    return ans;
}
ll co[N];
pair<int, int>arr[N];
multiset<int>st1,st2;
int n;
int main()
{
    FIO
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i].first;
    for(int i=0; i<n; i++)
        cin>>arr[i].second;

    sort(arr,arr+n);

    for(int i=0; i<n; i++)
    {
        if(arr[i].second>0)
        {
            co[i]+=st2.size();
            co[i] +=distance(st1.begin(),st1.upper_bound(arr[i].second));
            st1.insert(arr[i].second);
        }
        else if(arr[i].second<0)
        {
            int val=-arr[i].second;
            co[i]+=distance(st2.lower_bound(arr[i].second),st2.end());
            st2.insert(val);
        }
        else
        {
            co[i]+=st2.size();
             st1.insert(0);
        }
    }
    st1.clear();
    st2.clear();

    for(int i=n-1; i>=0; i--)
    {
        if(arr[i].second>0)
        {
            co[i]-=(distance(st1.lower_bound(arr[i].second),st1.end()));
            st1.insert(arr[i].second);
        }
        else if(arr[i].second<0)
        {
            int val=-arr[i].second;
            co[i]-=st1.size();
            co[i]-=distance(st2.begin(),st2.upper_bound(val));
            st2.insert(val);
        }
        else
        {
            co[i]-=st1.size();
            st2.insert(0);
        }
    }
    ll ans=0;
    for(int i=0; i<n; i++)
        ans+=co[i]*(ll)arr[i].first;
    cout<<ans;
}
