import sys N=int(input()) A=sorted(map(int,input().split())) if N<=2: print(0) sys.exit() from itertools import accumulate S=list(accumulate(A)) S2=list(accumulate(A[::-1])) ANS=0 for i in range(N//2): #print(S[i]+S2[i]-A[i+1]*(2*(i+1))) ANS=max(ANS,S[i]+S2[i]-A[i+1]*(2*(i+1))) print(ANS)