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

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

ans = sorted(ans)[::-1]
mem = np.array([True for i in range(n)])

total = 0
for x, ai in ans:
    ai[np.logical_not(mem)] = 0
    total += ai.max()    
    mem[ai.argmax()] = False
print(total)