n = int(input())
aaa = list(map(int, input().split()))
aaa_with_idx = list(zip(aaa, range(n)))
n2 = n // 2
ans = 0
for i in range(n2 + 1):
    srt = sorted(aaa_with_idx[i:], reverse=True)
    left = srt[:n2]
    right = sorted(srt[n2:] + aaa_with_idx[:i])

    tmp = 0
    for j, (a, k) in enumerate(left):
        tmp += a * abs(j - k)
    for j, (a, k) in enumerate(right, start=n2):
        tmp += a * abs(j - k)

    ans = max(ans, tmp)
print(ans)
