import heapq
import math

NN = 202020
MOD = 10**9+7
# MOD = 998244353
INF = float("inf")

n = int(input())
A = list(map(int, input().split()))
arr = [[] for _ in range(n)]

for i in range(n):
    for j in range(n):
        arr[i].append((-A[i]*abs(i-j), i, j))
    heapq.heapify(arr[i])

que = []
for i in range(n):
    heapq.heappush(que, heapq.heappop(arr[i]))

ans = [-1]*n
seen = set()
while que:
    val, i, j = heapq.heappop(que)
    if ans[j] == -1:
        ans[j] = -val
        seen.add(i)
    else:
        heapq.heappush(que, heapq.heappop(arr[i]))
    # print(val, i, j, ans, que)
    if len(seen) >= n:
        break

print(sum(ans))
