N = int(input()) A = sorted(map(int,input().split())) ans = 0 R = sum(A) for i in range(N): R -= A[i] ans += R - (N-i-1) * A[i] print(ans)