N = int(input())
A = list(map(int, input().split()))

l = 0; r = N-1
ans = 0
used = [False for _ in range(N)]
for _ in range(N):
    maxV = -1
    maxi = -1
    isr = False
    for i in range(N):
        if used[i]:
            continue
        if abs(r-i) >= abs(l-i):
            if maxV < A[i]*abs(r-i):
                isr = True
                maxV = A[i]*abs(r-i)
                maxi = i
        else:
            if maxV < A[i]*abs(l-i):
                isr = False
                maxV = A[i]*abs(l-i)
                maxi = i
    used[maxi] = True
    ans += maxV
    if isr:
        r -= 1
    else:
        l += 1
print(ans)