# -*- coding: utf-8 -*-
import sys

N = int(input())
A = list(map(int,input().split()))

B = []
for i,a in enumerate(A):
    B.append([a,i])
#%%
ans = 0
for i in range(1,max(2,N-1)):
    # しきりの位置
    
    res = 0
    left = 0
    right = N-1
    L = B[:i]
    L.sort(reverse = True)
    R = B[i:]
    R.sort(reverse = True)
    for val,idx in R:
        res += val*abs(idx-left)
        left += 1
    
    for val,idx in L:
        res += val*abs(right-idx)
        right -= 1
    ans = max(ans,res)
print(ans)
        