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(abs(c[0]-left), abs(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 abs(b[argmax][0]-left) > abs(right-b[argmax][0]):
        left += 1
    else:
        right -= 1
    ans += tmp
    del b[argmax]
    if left == right:
        break

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