N = int(input())
A = list(map(int, input().split()))
A2 = sorted(A, reverse=True)
A2 * N
answer = 0
for i,value in enumerate(A):
    for i2,value in enumerate(A2):
        answer += value * (i - i2)
print(answer)
