n=int(input())
arr=list(map(int,input().split()))
pos=[i for i in range(n)]
for _ in range(20):
  for i in range(n):
    for j in range(n):
      if arr[i]*abs(pos[j]-i)+arr[j]*abs(pos[i]-j)>arr[i]*abs(i-pos[i])+arr[j]*abs(j-pos[j]):
        pos[i],pos[j]=pos[j],pos[i]
ans=0
for i in range(n):
  ans+=arr[i]*abs(i-pos[i])
print(ans)