import heapq
N = int(input())
A = list(map(int, input().split()))
used = [False] * N
fixed = [0, N-1]
ans = 0
for _ in range(N):
    H = []
    for i in range(N):
        if used[i]:
            continue

        val = 0
        r = 1
        if A[i] * abs(i-fixed[0]) >= A[i] * abs(i - fixed[1]):
            val = A[i] * abs(i - fixed[0])
            r = 0
        else:
            val = A[i] * abs(i - fixed[1])
            r = 1

        heapq.heappush(H, (-val, i, r))
    val, index, r = H[0]
    ans += (-val)
    used[index] = True
    if r == 0:
        fixed[0] += 1
    else:
        fixed[1] -= 1
    del H
    # print(val, index, used)
print(ans)
