import math
N=int(input())
A_=list(map(int,input().split()))

N_list=[(j+1,k) for j,k in enumerate(A_)]
max_list=[]

for k in list(range(1,N+1)).reverse():
  for i in range(1,k):
    z=[math.abs(tup[0]-k)*tup[1] for tup in N_list]
    max_val=max(z)
    max_index=z.index(max_val)
    max_list.append(max_val)
    N_list.pop(max_index)
    
print(sum(max_list))
    