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

B = []
for i in range(N):
  B.append((A[i],i))

ans = 0
for part in range(0,N+1): #part未満のものは右に、それ以外は左に
  B_lt = B[:part]
  B_rt = B[part:]
  
  B_lt.sort(reverse = True)
  B_rt.sort(reverse = True)
  
  #print(B_lt)
  #print(B_rt)
  
  tmp = 0
  for i in range(len(B_lt)):
    tmp += B_lt[i][0] * ((N - 1 - i) - B_lt[i][1])
    #print(i, B_lt[i][0] * ((N - 1 - i) - B_lt[i][1]))
  for i in range(len(B_rt)):
    tmp += B_rt[i][0] * (B_rt[i][1] - i)
    #print(i, B_rt[i][0] * (B_rt[i][1] - i))
    
  ans = max(ans, tmp)
    
print(ans)
    
  
  
         
        