#include #define REP(i,n) for(int i=0,i##_len=int(n);i>N; vector a(N); REP(i, N) cin >> a[i]; sort(All(a)); vector S(N+1); REP(i,N) S[i+1]=S[i]+a[i]; ll ans=0; REP(i,N){ int l=0,r=N; while(l+1>1; if(i-mid<0){ r=mid; continue; } if(a[N-mid]>=a[i-mid]) l=mid; else r=mid; } ans=max(ans,S[N]-S[N-l]+(S[i]-S[i-l])-(2*l+1)*a[i]); if(i0) ans=max(ans,S[N]-S[N-l]+(S[i]-S[i-l-1]-(l+1)*(a[i]+a[i-1]))); } cout<