import heapq

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

S = [[] for _ in range(N)]
for i, a in enumerate(A):
    for j in range(N):
        S[i].append(abs(j-i)*a)

left = 0
right = N - 1
is_used = [False] * N
ans = 0
for i in range(N):
    temp = []
    for j in range(N):
        if is_used[j]:
            continue
        heapq.heappush(temp, [-S[j][left], 'l', j])
        heapq.heappush(temp, [-S[j][right], 'r', j])
    
    s, pos, j = heapq.heappop(temp)
    ans -= s
    is_used[j] = True
    if pos == 'l':
        left += 1
        if left > right:
            left = right
    else:
        right -= 1
        if right < left:
            right = left

print(ans)