N=int(input())
A=list(map(int,input().split()))
B=list(range(N))
Aleft=0
Aright=0
Aleftlist=[]
Arightlist=[]
Amax=0
Amaxmax=0
Apoint=0
Bpoint=0
check=0
for i in range(N):
  Amax=0
  Apoint=0
  Bpoint=0
  check=0
  for j in range((N-i)//2):
    if Amax<A[B[j]*(N-i-j):
      Amax=A[B[j]]*(N-i-j)
      Apoint=B[j]
      Bpoint=j
  for j in range((N-i)//2,N-i):
    if Amax<A[B[j]]*j:
      Amax=A[B[j]]*j
      Apoint=B[j]
      Bpoint=0
      check=1
  Amaxmax+=Amax
  A[Apoint]=0
  del B[Bpoint]
  if check==0:
     Aleft+=1
  else:
     Aright+=1
print(Amaxmax)
    