def valMove(i,val):
	global farR
	global farL
	left = abs(farR-i)
	right = abs(farL-i)
	return max(val*right,val*left)

# py abc163e.py
n = int(input())
arr = list(map(int,input().split()))
moved = {}
for i in range(n):
	moved[i] = False

farR = n-1
farL = 0

ans = 0

while True:
	toMove = -1
	for i in range(n):
		if not moved[i]:
			toMove = i
			moved[i] = True
			break
	if (toMove == -1):
		break

	direction = -1
	if abs(farR - toMove) > abs(farL - toMove):
		direction = 1 #right
	else:
		direction = 0 #left

	for i in range(n):
		if valMove(toMove,arr[toMove]) < valMove(i,arr[i]):
			toMove = i
			if abs(farR - toMove) > abs(farL - toMove):
				direction = 1 #right
			else:
				direction = 0 #left

	ans+= valMove(toMove,arr[toMove])
	arr[toMove] = -1
	if direction == 1:
		farR-=1
	else:
		farL+=1

print(ans)
