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

import heapq

ans = 0
doneX = [False]*N
doneY = [False]*N
hq = [(-a*abs(x-y),-a,x,y) for x,a in enumerate(A) for y in range(N)]
hq.sort()
heapq.heapify(hq)

hpop = heapq.heappop

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