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

B = [-1]*N
sum = 0
for i in range(N):
    C = [0]*N
    
    bf = B.index(-1)
    bb = (N-1) - B[::-1].index(-1)
    
    for j in range(N):
        C[j] = A[j] * max(abs(j-bf), abs(j-bb))

    k = C.index(max(C))
    sum += max(C)
    
    if abs(k-bf) > abs(k-bb):
        B[bf] = k
    else:
        B[bb] = k

    A[k] = 0

print(sum)