n=int(input())
l=[(j,i) for i,j in enumerate(map(int,input().split()))]
ans=[]
for x in range(1,n):
    L=l[:x]
    R=l[x:]
    L.sort()
    R.sort(reverse=True)
    y=0
    for i,j in enumerate(R+L):
        y+=j[0]*abs(j[1]-i)
    ans.append(y)
print(max(ans))