import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    ans=0
    used=[0]*N#動かしたか
    
    for i in range(N//2+3):
        for k in range(2):
            if k==0:
                target=N-1-i
            else:
                target=i
            maxx=0
            maxj=-1
            for j in range(N):
                if used[j]==0:
                    temp=A[j]*abs(target-j)
                    if temp>maxx:
                        maxx=temp
                        maxj=j
            ans+=maxx
            used[maxj]=1
            
    print(ans)
        
        
        

main()
