#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
a_list = list(map(int, input().split()))
start = 0
end = n - 1
ans = 0
for i in range(0, n):
    max_score = -1
    iti = -1
    flag = 0
    for j in range(0, n):
        if max_score < a_list[j] * abs(j - start):
            max_score = a_list[j] * abs(j - start)
            iti = j
            flag = -1
        if max_score < a_list[j] * abs(end - j):
            max_score = a_list[j] * abs(end - j)
            iti = j
            flag = 1
    a_list[iti] = 0
    if flag == -1:
        # print(iti+1, start+1, max_score)
        ans += max_score
        start += 1
        
    elif flag == 1:
        # print(iti+1, end+1, max_score)
        ans += max_score
        end -= 1
print(ans)
