#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
honke = 0
for border in range(n+1):
  ans = 0
  L = []
  for i in range(border):
    L.append((A[i],i))
  L.sort(reverse = True)
  for i in range(border):
    ans += (n-i-1-L[i][1])*L[i][0]


  R = []
  for i in range(border,n):
    R.append((A[i],i))
  R.sort(reverse = True)
  for i in range(n-border):
    ans += (R[i][1]-i)*R[i][0]
  honke = max(honke,ans)
print(honke)