import numpy as np

N = int(input())
A = list(map(int,input().split()))

ans = 0

a = np.arange(N*N).reshape(N,N)

for i in range(N):
    for j in range(N):
        if i == j:
            a[i,j] = 0
        else:
            a[i,j] = A[i] * abs(i-j)

# print(a)

for _ in range(N):
    # 最大値のインデックスを取得 idxには行、列がタプルで入る
    idx = np.unravel_index(np.argmax(a),a.shape)
    ans += a[idx]
    # 最大値がある行、列を削除
    a = np.delete(a,idx[0],axis=0)
    a = np.delete(a,idx[1],axis=1)
    # print(a)

print(ans)