import heapq

n=int(input())
arr=list(map(int,input().split()))
q=[]
for i in range(n):
  for j in range(n):
    heapq.heappush(q,(-arr[j]*abs(j-i),i,j))
ans=0
cnt=0
checked1=set()
checked2=set()
while 1:
  val,i,j=heapq.heappop(q)
  if i not in checked1 and j not in checked2:
    checked1.add(i)
    checked2.add(j)
    ans-=val
    cnt+=1
  if cnt==n:
    break
print(ans)