# E - Active Infants

import numpy as np

n = int(input())
A = np.array(list(int(x) for x in input().split()))

D = np.zeros((n, n),dtype=np.int64)

for i in range(n):
    for j in range(n):
        D[i][j] = A[i] * abs(i-j)

ans = 0
for _ in range(n):
    tmp = np.max(D)
    ans += tmp
    y, x = np.unravel_index(np.argmax(D), D.shape)
    D[y, :] = 0
    D[:, x] = 0

print(ans)