n=int(input(''))
a=input('')
a=a.split(' ')
q=[]
for i in range(n):
    a[i]=int(a[i])
    q.append(0)

s=0
u=-1
if len(a)%2==0 or len(a)%2==1:
    for i in range(int(len(a)/2)):
        o=0
        oj=0
        for j in range(len(a)):
            if q[j]==0:
                m=a[j]*(i-j)
                if m<0:
                    m=m*(-1)
                if o<m:
                    o=m
                    oj=j
        q[oj]=1
        s=s+o

        o=0
        oj=0
        for j in range(len(a)):
            if q[j]==0:
                m=a[j]*(len(a)+u-j)
                if m<0:
                    m=m*(-1)
                if o<m:
                    o=m
                    oj=j
            
        u=u-1
        q[oj]=1
        s=s+o
    
    print(s)