import math
import queue
import itertools as it

def readInt():
	return int(input())
 
def readInts():
	return list(map(int, input().split()))
 
def readChars():
	return input().split()

#def comba(n):#1~nの組み合わせ
	#for i in range(1,n+1):
		#for j in range(1,n+1):

n = readInt()
a = readInts()

x = list(it.permutations(range(1,n+1),n))

point = []

for j in range(len(x)):
	p = 0
	for i in range(n):
		p += abs(x[j][i]-(i+1))*a[i]
		point.append(p)
		#print(p , x[j])

print(max(point))