#!/usr/bin/env python3
import sys
from itertools import accumulate
import itertools
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9+7

N = int(input())
A = list(map(int, input().split()))
AA = list(enumerate(A))
acc = [0]+list(accumulate(A))


mt = -INF
for k in range(1, N):
    # k以降を手前へ, kまでを後ろへ
    kpre, kpost = AA[:k], AA[k:]
    kpre.sort(key=lambda x: x[1])
    kpost.sort(key=lambda x: x[1], reverse=True)
    tot = 0
    for ii, (i, v) in enumerate(kpre):
        tot += abs(ii+(N-k)-i)*v
    for ii, (i, v) in enumerate(kpost):
        tot += abs(ii-i)*v
    # print(kpre, kpost, tot)
    if tot > mt:
        mt = tot
        # print("!", kpost, kpre, tot)
print(mt)
