import math
import fractions
import collections
import itertools
import pprint
N=int(input())
A=list(map(int,input().split()))

st=[-1]*N
en=[-1]*N
s=[[0,[0,0]] for _ in range(N*N)]
for i in range(N):
    for j in range(N):
        s[i*N+j][0]=A[i]*abs(i-j)
        s[i*N+j][1][0]=i
        s[i*N+j][1][1] = j
s.sort(key=lambda x:x[0],reverse=True)
#print(s)
cnt=0
for i in range(len(s)):
    if (st[s[i][1][0]]==-1)and(en[s[i][1][1]]==-1):
        cnt=cnt+s[i][0]
        st[s[i][1][0]]=0
        en[s[i][1][1]]=0
print(cnt)