ll n,t,z,l,a[2d5],s[3d5];{rd(n,a(n));sortA(n,a);s[1..n]=t+=a[0..];rep[a,i](x,n)l=bsearch_max[ll,l,0,i](a[i-l]+a[n-l]>2x),z>?=t-s[n-l]+s[i]-s[i-l]-l*2x;wt(z);}