import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

tab = [ [0] * len(A) for _ in range(len(A))]
for i in range(len(A)):
    for j in range(len(A)):
        tab[j][i] = (abs(j-i)*(A[i]), i)

for t in tab:
    t.sort()

s = set(range(len(A)))

ans = [-1] * len(A)
idx = [-1] * len(A)
del_j = set()
while s:
    max_i = -1
    max_score = -float('inf')
    for i in s:
        while tab[i][-1][1] in del_j:
            tab[i].pop()
        score, j = tab[i][-1]
        if max_score < score:
            max_score = score
            max_i = i
    score, j = tab[max_i].pop()
    idx[max_i] = j
    ans[max_i] = score
    s.remove(max_i)
    del_j.add(j)

print(sum(ans))