import sys

sys.setrecursionlimit(10**4)


def dfs(sude,sho,dai,ki):
    #print("新しい",sude,sho,dai,ki)
    global a,n
    #print(a,n)
    if(n==ki):
        return 0
    koho=[]
    saidai=-1
    for i in range(n):
        if(sude[i]):
            continue
        mae=abs(sho-i)
        usiro=abs(dai-i)
        #print(sho,dai,i,mae,usiro)
        if(mae<usiro):
            if(a[i]*usiro>saidai):
                koho=[[i,1]]
                saidai=a[i]*usiro
            elif(a[i]*usiro==saidai):
                koho.append([i,1])
        elif(usiro<mae):
            if(a[i]*mae>saidai):
                koho=[[i,-1]]
                saidai=a[i]*mae
            elif(a[i]*mae==saidai):
                koho.append([i,-1])
        else:
            if(a[i]*mae>saidai):
                saidai=a[i]*mae
                koho=[[i,-1],[i,1]]
            elif(a[i]*mae==saidai):
                koho.append([i,-1])
                koho.append([i,1])
    result_max=-1
    for k in koho:
        sude_co=sude[:]
        sude_co[k[0]]=True
        kekka=-1
        if(k[1]==-1):
            kekka=dfs(sude_co,sho+1,dai,ki+1)+a[k[0]]*abs(sho-k[0])
        else:
            kekka=dfs(sude_co,sho,dai-1,ki+1)+a[k[0]]*abs(dai-k[0])
        if(result_max<kekka):
            result_max=kekka
    #print(koho)
    return result_max


n=int(input())
a=list(map(int,input().split()))

ans=0
sude=[False]*n

print(dfs(sude,0,n-1,0))

#sho=0
#dai=n-1
#for i in range(n):
#    saiyo_val=-1
#    saiyo_num=-1
#    tiisaiho=False
#    for j in range(n):
#        if(sude[j]):
#            continue
#        saidai_kyori=max(abs(sho-j),abs(dai-j))
#        if(a[j]*saidai_kyori>saiyo_val):
#            saiyo_val=a[j]*saidai_kyori
