from heapq import heappop, heappush

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

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

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))

def main():
    ans = 0
    for _ in range(N):
        MAXH = {"happy":-1, "place":0, "child":0}
        for i in range(N):
            if place[i]: continue
            h, c = heappop(info[i])
            if MAXH["happy"] < (-1) * h:
                MAXH["happy"] = (-1) * h
                MAXH["place"] = i
                MAXH["child"] = c
            heappush(info[i], (h, c))
        
        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)

if __name__ == "__main__":
    main()