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)
#print(dp)



cunter = 0
for s in range(N):
    k = []
    l = []
    for i in dp:
        k.append(max(i))
        l.append(i.index(max(i)))
    counter += max(k)
    for u in range(N):
        dp[u][l[k.index(max(k))]] = -1
        dp[k.index(max(k))][u] = -1
    #print(dp)
print(counter)