n = int(input())
a = list(map(int, input().split()))
b = {}
for i, v in enumerate(a):
    b[i] = v
l = 0
r = n - 1
ans = 0
while len(b) > 0:
    mi = 0
    mv = 0
    mov = 10 ** 9 + 1
    ml = False
    for i, v in b.items():
        if abs(i - l) > abs(i - r):
            tv = v * abs(i - l)
            tl = True
        else:
            tv = v * abs(i - r)
            tl = False
        if tv > mv or (tv == mv and v < mov):
            mi = i
            mv = tv
            ml = tl
            mov = v
    if ml:
        l += 1
    else:
        r -= 1
    ans += mv
    b.pop(mi)
print(ans)
