n=int(input())
arr=list(map(int,input().split()))
l,r=0,n-1
ans=0
checked=[0]*n
for _ in range(n):
  pos,val=0,0
  for i in range(n):
    if checked[i]==1:
      continue
    tmp=arr[i]*max(i-l,r-i)
    if tmp>val:
      pos=i
      val=tmp
  checked[pos]=1
  ans+=val
  if pos-l>r-pos:
    l+=1
  else:
    r-=1
print(ans)