# coding: utf-8
N = int(input())
_A = list(map(int, input().split()))
A = []
for i, a in enumerate(_A, 1):
    A.append((i, a))

dp = [0] * N
for i in range(N):
    _left = A[0:i]
    _right = A[i:]
    perm = list(range(1, N + 1))
    left = sorted(_left, key=lambda x: x[1], reverse=True)
    right = sorted(_right, key=lambda x: x[1], reverse=True)

    happiness = 0

    idx = N
    for k, Ak in left:
        happiness += (idx-k) * Ak
        idx -= 1
    idx = 1
    for k, Ak in right:
        happiness += (k - idx) * Ak
        idx += 1
    dp[i] = happiness


print(max(dp))