N = int(input())
A = list(map(int, input().split()))

ans = 0

#SEIRETSU = []
#for _ in range(N):
  #SEIRETSU.append(0)

left = 0
right = N-1


for i in range(N):
  LR = 0
  tmp = 0
  J = 0
  for j in range(N):
    if tmp < (A[j]*abs(j-left)):
      tmp = A[j]*abs(j-left)
      LR = 0
      J = j
    
    if tmp < (A[j]*abs(j-right)):
      tmp = A[j]*abs(j-right)
      LR = 1
      J = j

  ans += tmp
  if LR == 0:
    A[J] = 0
    #SEIRETSU[left] = tmp
    left += 1

  else:
    A[J] = 0
    #SEIRETSU[right] = tmp
    right -= 1

  #print(SEIRETSU)
  #print(A)


print(ans)
