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

max = n - 1
min = 0
li = [0] * n
cnt = 0
ans = 0
while cnt < n:
    maxa = None
    for i in range(0, n):
        if a[i] == None: continue
        l = False
        if a[i] * abs(i - min) > a[i] * abs(i - max):
            l = True
            t = a[i] * abs(i - min)
        else :
            t = a[i] * abs(i - max)
        if maxa == None or t > maxa:
            maxa = t
            maxid = i
            l2 = l
    if l2 == True :
        li[min] = a[maxid]
        min += 1
    else :
        li[max] = a[maxid]
        max -= 1
    ans += maxa
    a[maxid] = None
    #print(li, a, maxa)
    cnt += 1
print(ans)
