n=int(input()) t=list(map(int,input().split())) t.sort() a=0 for i in range(n): a+=t[i]*i a-=t[i]*(n-1-i) print(a)