N = int(input())
As = list(map(int, input().split()))

enumAs = list(enumerate(As))
maxscore = 0
for i in range(1, N):
    As_former = enumAs[:i]
    As_latter = enumAs[i:]
    possibleAs = sorted(As_latter, key = lambda t:t[1], reverse = True) + sorted(As_former, key = lambda t:t[1])
    score = sum(map(lambda A: A[1][1] * abs(A[0] - A[1][0]), enumerate(possibleAs)))
    maxscore = max(score, maxscore)

print(maxscore)