N = int(input())
L, R = 0, N - 1
A = [[a, -1] for i, a in enumerate(list(map(int, input().split())))]
for _ in range(N):
    max_p, max_i = -1, -1
    for i in range(N):
        if A[i][1] == -1 and A[i][0] * max(abs(i - L), abs(i - R)) > max_p:
            max_p, max_i = A[i][0] * max(abs(i - L), abs(i - R)), i
    if abs(max_i - L) > abs(max_i - R):
        A[max_i][1], L = L, L + 1
    else:
        A[max_i][1], R = R, R - 1
print(sum([A[i][0] * abs(i - A[i][1]) for i in range(N)]))
