#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; int main(){ int n; cin>>n; vector A(n),B(n); vector> C(n); rep(i,n) cin>>A[i]; rep(i,n) cin>>B[i]; rep(i,n) C[i]={A[i],B[i]}; sort(ALL(C)); vector s(n+1); rep(i,n) s[i+1]=s[i]+C[i].second; ll m=(s[n]+1)/2; ll x=C[lower_bound(ALL(s),m)-s.begin()-1].first; ll ans=0; rep(i,n){ ans+=C[i].second*abs(C[i].first-x); } cout<