#include using namespace std; using ll = long long; int main() { ll n; cin>>n; vector v(n); for(ll i=0;i>v[i]; } sort(v.begin(),v.end()); ll S=v[0]+v[1]+v[n-1]; ll odd=1; ll even=2; ll cen=0; ll max=0; ll tmp; for(ll i=4;i<=n;++i){ if(i%2==1){ odd++; cen=v[even]; S+=v[n-odd]; tmp=cen*i; }else{ even++; S+=v[even]; cen=v[even]+v[even]; tmp=cen*i/2; } max=max<(S-tmp)?(S-tmp):max; } cout<