n,*a = map(int,open(0).read().split())
a = list(zip(a,range(n)))
m = n // 2
ans = 0
l = n//3
for j in range(m-l,m+l+1):
  a1 = sorted(a[j:n],key=lambda x:x[0],reverse=True)+sorted(a[0:j],key=lambda x:x[0])
  ans = max(ans,sum([a1[i][0]*abs(i-a1[i][1]) for i in range(n)]))
print(ans)