n = int(input())
a = list(map(int, input().split()))
b = [(i, a[i]) for i in range(n)]
left, right = 0, n-1

ans = 0
while True:
    happiness = [max(c[0]-left, right-c[0]) * c[1] for c in b]
    # max/argmax
    tmp, argmax = 0, 0
    for i in range(len(b)):
        if happiness[i] > tmp:
            tmp, argmax = happiness[i], i
    if b[argmax][0]-left > right-b[argmax][0]:
        left += 1
    else:
        right -= 1
    ans += tmp
    del b[argmax]
    if left == right:
        break

ans += max(b[0][0]-left, right-b[0][0]) * b[0][1]
print(ans)
