import copy

n=int(input())
a0=input().split()
al=[int(a) for a in a0]
left0=[x for x in range(n)]

def max(l,left,hp):
  if left==[]:
    return hp
  else:
    re=0
    rel=[]
    nextp=len(l)#0--n-1
    for x in left:
      l2=copy.deepcopy(l)
      left2=copy.deepcopy(left)
      l2.append(x)
      left2.remove(x)
      hp2=hp+al[x]*abs(x-nextp)
      newhp=max(l2,left2,hp2)
      if re<newhp:
        re=newhp
    return re
        
hpz=max([],left0,0)
print(hpz)