import heapq

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

n = int(input())
A = list(map(int, input().split()))
que = []
for i in range(len(A)):
    for j in range(len(A)):
        que.append((-A[i]*abs(i-j), abs(i-j), i, j))

heapq.heapify(que)
ans = [-1]*len(A)
seen = set()
while que:
    val, _, i, j = heapq.heappop(que)
    # print(val, x)
    if ans[j] == -1 and i not in seen:
        ans[j] = -val
        seen.add(i)
    # print(val, j, ans)

# print(ans)
print(sum(ans))
