import numpy as np
import math

N = int(input())
A = [int(x) for x in input().split()]
B = list(range(1,N+1))
C = [0]*N
sum = 0

for i in range(N):
    d=0
    l=0
    m_k=0
    j = np.argmax(A)
    
    for k in B:
        l = abs(k-(j+1))
        if l > d:
            d = l
            m_k = k
    sum = sum + d*A[j]
    C[m_k-1]=A[j]
    B.remove(m_k)
    A[j]=0
print(sum)