int n,a[2d5],b[2d5],e; ll c,d,z; { rd(n,a(n),b(n)); sortA(n,a,b); c=sum(b(n)); rep(i,n) { d+=b[i]; if(d*2<=c){ e=i; } } rep(i,n) { z+=1ll*b[i]*(i<=e?a[e]-a[i]:a[i]-a[e]); } wt(a[e],z); }