def cur(ans,l,r,p):
    for i in range(p,n):
        a=inf[i][0];x=inf[i][1]
        if x-l>=r-x: ans[l]=[a,x];l+=1
        elif x-l<r-x: ans[r]=[a,x];r-=1
        else:
            tmpansl=[[ans[i][0],ans[i][1]] for i in range(n)]
            tmpansr=[[ans[i][0],ans[i][1]] for i in range(n)]
            tmpansl[l]=[a,x]
            tmpansr[r]=[a,x]
            return max(cur(tmpansl,l+1,r,p+1),cur(tmpansr,l,r-1,p+1))

    x=0
    for i in range(n):
        x+=ans[i][0]*abs(ans[i][1]-i)
    return x



n=int(input())
a=list(map(int,input().split()))
inf=[[a[i],i] for i in range(n)]
inf.sort(reverse=True)
ans=[False]*n

print(cur(ans,0,n-1,0))