#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define mp make_pair
#define w first
#define f second
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)


bool cmp(pii a, pii b){
	return a.w*b.f<a.f*b.w;
}

/********** Main()  function **********/
int main(){
	IOS();
	pii item[100005];
	ll w[100005] = {}, f[100005]={};
	ll n;cin>>n;
	for(ll i=0;i<n;i++){
		cin>>w[i];
	}
	for(ll i=0;i<n;i++){
		cin>>f[i];
	}
	for(ll i=0;i<n;i++){
		item[i] = mp(w[i],f[i]);
	}
	sort(item,item+n,cmp);
	ll on = 0,ans = 0;
	for(ll i=0;i<n;i++){
		ans += on * item[i].f;
		on += item[i].w;
	}
	cout<<ans<<endl;
	return 0;
}

ZJ

pixiv