import numpy as np
n=int(input())
a=list(map(int,input().split()))
dp=np.array([[0 for _ in range(n)] for _ in range(n)])
for i in range(n):
    for j in range(n):
        dp[i][j]=abs(i-j)*a[i]
#print(dp)
ans=0
nu=n
for i in range(n):
    ind=np.argmax(dp)
    row=ind//nu
    col=ind%nu
    ans+=dp[row][col]
    dp=np.delete(dp,row,0)
    dp=np.delete(dp,col,1)
    nu-=1
    #print(dp)
    #print()

print(ans)
