from heapq import heappop, heappush

N = int(input())
A = [int(i) for i in input().split()]

"""
各地点について
(うれしさ、幼児番号)
をまとめる

貪欲に決定していく
"""

info = [[] for _ in range(N)]
for i,a in enumerate(A):
    for j in range(N):
        heappush(info[j], ((-1) * a * abs(i - j), i))

place = [False] * N
child = [False] * N

ans = 0
for _ in range(N):
    MAXH = {"happy":-1, "place":0, "child":0}
    for i in range(N):
        if place[i]: continue
        if MAXH["happy"] < (-1) * info[i][0][0]:
            MAXH["happy"] = (-1) * info[i][0][0]
            MAXH["child"] = info[i][0][1]
            MAXH["place"] = i
    
    place[MAXH["place"]] = True
    child[MAXH["child"]] = True

    heappop(info[MAXH["place"]])

    ans += MAXH["happy"]

    for i in range(N):
        if place[i]: continue
        while info[i]:
            h, c = heappop(info[i])
            if not child[c]:
                heappush(info[i], (h, c))
                break
            
print(ans)