N = int(input())
X = [(i+1, x) for i, x in enumerate(map(int, input().split()))]
R = 0
for i in range(1, N):
    A, B = X[:i], X[i:]
#    print(A, B)
    A = sorted(A, key=lambda x: x[1])[::-1]
    B = sorted(B, key=lambda x: x[1])[::-1]
    r = 0
    for i in range(len(A)):
        j, x = A[i]
        r += x*abs(N-i-j)
    for i in range(len(B)):
        j, x = B[i]
        r += x*abs(j-(i+1))
    R = max(R, r)

print(R)
