N = int(input())
A = list(map(int, input().split()))
L = [(A[i], i) for i in range(N)]
res = 0
for i in range(N - 1):
    tres = 0
    l = L[: i + 1]
    r = L[i + 1 :]
    l.sort()
    r.sort(reverse=True)
    for j in range(i + 1):
        tres += abs(j + (N - i - 1) - l[j][1]) * l[j][0]
    for j in range(N - i - 1):
        tres += abs(j - r[j][1]) * r[j][0]
    res = max(res, tres)
print(res)
