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

empty=[True]*N
seen=[False]*N
arr=[]
for i in range(N):
    for j in range(N):
        arr.append((A[j]*abs(j-i),i,j))
arr.sort(reverse=True)
ans=0
res=[0]*N
for p,x,y in arr:
    if empty[x] and not seen[y]:
        ans+=p
        res[x]=y
        seen[y]=True
        empty[x]=False
print(ans)