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

import heapq

ans = 0
doneX = [False]*N
doneY = [False]*N
hq = []
hpush = heapq.heappush
hpop = heapq.heappop
for x,a in enumerate(A):
    for y in range(N):
        hpush(hq,(-a*abs(x-y),x,y))

while hq:
    a,x,y = hpop(hq)
    if doneX[x] or doneY[y]:continue
    ans -= a
    doneX[x] = True
    doneY[y] = True
print(ans)