import heapq

N = int(input())
A = list(map(int, input().split(' ')))

ans = 0
que = []
for i in range(N):
    for j in range(N):
        # Ai -> j
        heapq.heappush(que, (- abs(i - j) * A[i] , i,  j))

occupied = set()
used = set()

while len(occupied) < N and len(used) < N:
    activiness, use, pos = heapq.heappop(que)
    if pos in occupied or use in used:
        continue
    ans += -activiness
    occupied.add(pos)
    used.add(use)

print(ans)