import itertools

N = int(input())
A = list(map(int, input().split()))
A2 = sorted(A)

all = list(itertools.permutations(A, N))

end = []
for pattern in all:
    answer = []
    count = N
    for i,value in enumerate(pattern):
        answer.append(value * (count - i))
        count -= 1
    end.append(sum(answer))

print(max(end))
