N=int(input()) A=sorted(map(int,input().split())) 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))) A=A[::-1] S=list(accumulate(A)) S2=list(accumulate(A[::-1])) 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)