n = int(input())
a = list(map(int, input().split()))

ans = 0
j = 0
k = n-1

for i in range(n):
    l = 0
    for id, v in enumerate(a):
        if (max(id+j, k-id))*v > l:
            l = (max(id-j, k-id)) * v
            mid = id
            mv = v
    ans = ans + l
    a[mid] = 0
    if  mid-j > k-mid:
        j = j + 1
    else:
        k = k - 1

print(ans) 