# -*- coding: utf-8 -*-

# 整数の入力
a = int(input())
# # スペース区切りの整数の入力
# strs = input().split()

nums = list(map(int, input().split()))

vilist = []
for i in range(a):
    vilist.append((nums[i], i))
vilist = sorted(vilist, key=lambda vi: vi[0], reverse=True)

# dp[x][y]をx人を左から活性度順に並べて、y人を右から活性度順に並べた状態のスコア最大値とする
dp = []
for i in range(a + 1):
    ls = []
    for j in range(a + 1):
        ls.append(0)
    dp.append(ls)

# dp[i][j]を考える
for i in range(a+1):
    for j in range(a+1-i):
        if i == 0 and j == 0:
            continue
        # k = (i + j - 1)番目の人
        k = i + j - 1

        if j == 0:
            dp[i][0] = dp[i-1][0] + vilist[k][0] * abs(vilist[k][1] - i + 1)
        elif i == 0:
            dp[0][j] = dp[0][j-1] + vilist[k][0] * abs(a - j - vilist[k][1])
        else:
            dp[i][j] = max(dp[i-1][j] + vilist[k][0] * abs(vilist[k][1] - i + 1),
                           dp[i][j-1] + vilist[k][0] * abs(a - j - vilist[k][1]))

max_v = 0
for x in dp:
    max_x = max(x)
    if max_v < max_x:
        max_v = max_x

print(max_v)
