import sys

# 整数を一つ入力
N = int(input())
# スペース区切りの整数をリストに入力
t = [int(x) for x in input().split()]

A = []
for i in range(N):
    A.append([t[i],i+1,0])

A.sort(reverse=True)
for i in range(N):
    if i == 0:
        A[N-1-i][2] = A[N-1-i][0]
    else:
        A[N-1-i][2] = A[N-1-i+1][2] + A[N-1-i][0]


r_max = 0

sys.setrecursionlimit(2500)
def test(i,r,h,l):
    global r_max
    if r_max - r > A[i][2]*(h-l):
        return
    if i == N-1:
        r_max = max(r_max, r+abs(A[i][1]-h)*A[i][0])
    else:
        test(i+1,r+abs(A[i][1]-h)*A[i][0],h-1,l)
        test(i+1,r+abs(A[i][1]-l)*A[i][0],h,l+1)

test(0,0,N,1)

print(r_max)