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

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

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