from operator import itemgetter
import sys
sys.setrecursionlimit(10**5)

def f(x, po, h, t, ple):
    if po=='h':
        ple+=B[x][1]*abs(B[x][0]-h)
        h+=1
    else:
        ple+=B[x][1]*abs(B[x][0]-t)
        t-=1
    if h>t:
        return ple
    
    ans1=f(x+1, 'h', h, t, ple)
    ans2=f(x+1, 't', h, t, ple)
    return max(ans1, ans2)

N=int(input())
A=list(map(int, input().split()))
B=[[i, A[i]] for i in range(N)]
B=sorted(B, key=itemgetter(1), reverse=True)
h=0
t=N-1
ans1=f(0, 'h', h, t, 0)
ans2=f(0, 't', h, t, 0)
print(max(ans1, ans2))