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)):
    a=s[i][1][0]
    b=s[i][1][1]
    c=s[i][0]
    if (st[a]==-1)and(en[b]==-1):
        cnt=cnt+c
        st[a]=0
        en[b]=0
print(cnt)