#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } signed main(){ int n;cin>>n; using P=pair; vector

v(n); rep(i,n) cin>>v[i].first; rep(i,n) cin>>v[i].second; sort(ALL(v)); ll s=0; rep(i,n) s+=v[i].second; ll t=0; ll argmin; rep(i,n){ t+=v[i].second; if(t>=s/2){ argmin=v[i].first; break; } } ll res=0; rep(i,n) res+=abs(argmin-v[i].first)*v[i].second; cout<