import sys

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

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

#二次元配列初期化
ar = [[-1 for i2 in range(N)] for i1 in range(N)]

A.sort(reverse=True)

r_max = 0

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

test(0,0,N-1,0)

print(r_max)