

n = 0
a = []

def format_input(filename = None):
	global n
	global a
	if filename == None:
		n = int(input())
		a = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(2, 2 * 10**3)
		a = [rng(1, 10**9) for i in range(n)]
		print(n)
		print(' '.join(list(map(str, a))))

def get_answer():
	b = [0] * n
	max_happiness = []
	for i in range(n):
		b[i] = a[i]
		max_happiness.append(a[i]*max(i, n-1 - i))

	answer = 0
	left = 0
	right = n-1
	for i in range(n):
		k = max_happiness.index(max(max_happiness))
		answer += max_happiness[k]
		b[k] = 0
		if k - left < right - k:
			right -= 1
		else:
			left += 1 
		for i in range(n):
			max_happiness[i] = b[i] * max(i - left, right - i)

	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)
