N=int(input())
A=list(map(int,input().split()))
L=[]
for i in range(N):
    L.append([A[i],i])
#print(L)
ans=0
import copy
from collections import deque
for i in range(1,N):
    cnt=0
    a=copy.deepcopy(L[:i])
    b=copy.deepcopy(L[i:])
    #print(a,b)
    a.sort(reverse=True)
    b.sort(reverse=True)
    #print("ab",a,b)
    A=deque([N-len(a)+j for j in range(len(a)) ])
    B=deque([j for j in range(len(b))])
    #print(A)
    #print(B)
    for j in range(len(a)):
        if abs(a[j][0]*(a[j][1]-A[0]))>abs(a[j][0]*(a[j][1]-A[-1])):
            cnt+=abs(a[j][0]*(a[j][1]-A[0]))
            A.popleft()
        else:
            cnt+=abs(a[j][0]*(a[j][1]-A[-1]))
            A.pop()
    #print("A",cnt)
    for j in range(len(b)):
        if abs(b[j][0]*(b[j][1]-B[0]))>abs(b[j][0]*(b[j][1]-B[-1])):
            cnt+=abs(b[j][0]*(b[j][1]-B[0]))
            B.popleft()
        else:
            cnt+=abs(b[j][0]*(b[j][1]-B[-1]))
            B.pop()
    #print(cnt)
    if ans<cnt:
        ans=cnt
print(ans)
