import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
C=[False]*n

l,r=0,n-1
ans=0
for _ in range(n):
  score=0
  ii=0
  ss=0
  for i in range(n):
    if C[i]:
      continue
    else:
      a=A[i]
      if score<a*max(abs(l-i),abs(r-i)) or (score==a*max(abs(l-i),abs(r-i)) and ss>a):
        score=a*max(abs(l-i),abs(r-i))
        ii=i
        ss=a
        if abs(l-i)>abs(r-i):
          dir=-1
        else:
          dir=1

  ans+=score
  if dir==-1:
    l+=1
  else:
    r-=1
  C[ii]=True
print(ans)


