import numpy as np
n = int(input())
a = list(map(int, input().split()))

ans = []
sorts = []
for i in range(n):
    temp = [a[i] * abs(i - j) for j in range(n)]
    ans.append(temp)
    sorts.append(max(temp))

sorts = np.argsort(sorts)
ans = np.array(ans)[sorts][::-1]

mem = np.array([True for i in range(n)])
total = 0
for ai in ans:
    ai[np.logical_not(mem)] = 0
    total += ai.max()    
    mem[ai.argmax()] = False
print(total)