from heapq import heappop, heappush

N, *A = map(int, open(0).read().split())

pq = []
for i in range(N):
    for j in range(N):
        heappush(pq, (-A[i] * abs(i - j), i, j))

used = [False] * N
filled = [False] * N
ans = 0
while pq:
    v, i, j = heappop(pq)
    if used[i] or filled[j]:
        continue

    ans += v
    used[i] = True
    filled[j] = True
    
print(-ans)
