import numpy as np
N = int(input())
A = list(map(int,input().split()))

li1 = [i+1 for i in range(N)]
li2 = []
counter = 0

dp =[[0 for i in range(N)] for k in range(N)]
#dp[i][k] を　インデックス番号i からkに移動したときの得点とする

for i in range(N):
    for k in range(N):
        dp[i][k] = A[i]*max(i-k,k-i)

dp = np.array(dp)
i=0
k=0
counter = 0
for u in range(N):
    i,k = np.where(dp==dp.max())
    counter += dp.max()
    arr=np.delete(dp,i,0)
    dp=np.delete(arr,k,1)
print(counter)