import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
a = list(map(int,input().split()))

b = []
for i in range(n):
  b.append((a[i],i))
b.sort(reverse = True)

ans = 0
def f(l,r,i,h):
  global ans
  if i == n:
    ans = max(ans,h)
    return
  x = b[i][0]
  y = b[i][1]
  f(l+1,r,i+1,h+x*abs(y-l))
  f(l,r-1,i+1,h+x*abs(y-r))

f(0,n-1,0,0)
print(ans)