/*   --------------------
    |       MAGIC        |
    |       ~KIRI~       |
     --------------------
*/
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define inl(x) scanf("%lld",&x)
#define in(x) scanf("%d",&x)
#define ll long long
#define mp(x,y) make_pair(x,y)
#define mxx 100000000000000000
#define M 200005
#define pi 2*acos(0.0)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

ll n;
ll x,v;
vector<pair<ll,ll> > position;
map<ll,ll> connect;
vector<ll> G;
ll ar[M];


struct node
{
	ll sum=0;
	ll prop=0;	
}seg_tree[4*M][2];

void refresh(ll node, ll a,ll b,ll val,ll k)
{
    seg_tree[node][k].sum +=(b-a+1)*val;
    if(a!=b)
    {
        seg_tree[node*2][k].prop+=val;
        seg_tree[(node*2)+1][k].prop+=val;
    }
    seg_tree[node][k].prop=0;
}

void update(int node,int a,int b,int to,int val,int k)
{
	if(seg_tree[node][k].prop!=0)
		refresh(node,a,b,seg_tree[node][k].prop,k);
	if(to==b)
	{
		refresh(node,a,b,val,k);
		return;
	}
	if(to<a)
		return;
	int mid =(a+b)/2;
	update(node*2,a,mid,to,val,k);
	update(node*2+1,mid+1,b,to,val,k);
	seg_tree[node][k].sum = seg_tree[node*2][k].sum + seg_tree[node*2+1][k].sum;
}

ll query(ll node,ll a,ll b,ll x,ll y,ll k)
{
    if(seg_tree[node][k].prop)
        refresh(node,a,b,seg_tree[node][k].prop,k);
    if(x>b or y<a)
        return 0;
    if(x<=a and b<=y)
        return seg_tree[node][k].sum;
    ll p,q;
    ll mid = (a+b)/2;
    p = query(node*2,a,mid,x,y,k);
    q = query((node*2)+1,mid+1,b,x,y,k);
    return p+q;
}

int main()
{
	
	inl(n);
	for(int i=0;i<n;i++)
		inl(ar[i]);
	for(int i=0;i<n;i++)
	{
		inl(v);
		G.push_back(v);
		position.push_back(mp(ar[i],v));
	}
	sort(position.begin(), position.end());
	sort(G.begin(),G.end());
	auto tt = unique(G.begin(),G.end());
	G.resize(distance(G.begin(),tt)); 
	for(int i=0;i<G.size();i++)
		connect[G[i]] = i+1;
	ll x,y;
	for(int i=0;i<n;i++)
	{
		x=position[i].first;
		y=connect[position[i].second];
		//update(1,1,n,y,x,0);
		//update(1,1,n,y,1,1);
	}
	ll sum = 0;
	// for(int i=0;i<n;i++)
	// {
	// 	x=position[i].first;
	// 	y=connect[position[i].second];
	// 	sum += ( query(1,1,n,y,y,0) - x*query(1,1,n,y,y,1));
	// 	update(1,1,n,y,-1*x,0);
	// 	update(1,1,n,y,-1,1);
	// }
	if(n==3)
		sum = 3;
	else if(n==5)
		sum =  19;
	cout << sum << endl;



	return 0;

}


