n=int(input())
a=[[i,int(j)] for i,j in enumerate(input().split())]
a.sort(key=lambda x:x[1],reverse=True)
dp=[[0]*(n+1) for _ in range(n+1)]
for i in range(n):
  idx,v=a[i]
  dp[i+1][0]=dp[i][0]+v*abs(idx+1-n+i)
for i in range(n):
  idx,v=a[i]
  for j in range(1,i+2):
    dp[i+1][j]=max(dp[i][j-1]+v*abs(idx-j+1),dp[i][j]+v*abs(idx+1-n+i-j))
print(max(dp[-1]))