n = int(input()) a = [int(i) for i in input().split()] a.sort() rui = [0]*(n+1) for i in range(n): rui[i+1] = rui[i]+a[i] #print(rui) tmp = 0 now = a[0] ans = 0 for i in range((n+1)//2): tmp = 0 #bfr = a[i] aft = a[i+1] #chu = aft tmp += (rui[i+1]-rui[0])-aft*(i+1) #print(tmp,"t1") tmp += (rui[n]-rui[n-i-1])-aft*(i+1) #print(tmp,"t2") ans = max(ans,tmp) #print(tmp) print(ans)