import numpy as np

N = int(input())

A_list = np.array(list(map(int, input().split())))
arg_list = np.argsort(-A_list)

r_fill = 0
l_fill = 0

max_all = 0
for i in range(N):
    max_value = 0
    max_idx = 0
    tmp_l_fill = 0
    tmp_r_fill = 0
    for idx, j in enumerate(arg_list):
        tmp_max = A_list[j] * max(j-l_fill, N-j-1-r_fill)

        if tmp_max > max_value:
            max_idx = idx
            max_value = tmp_max
            if j-l_fill > N-j-1-r_fill:
                tmp_l_fill = 1
                tmp_r_fill = 0
            else:
                tmp_r_fill = 1
                tmp_l_fill = 0

    r_fill += tmp_r_fill
    l_fill += tmp_l_fill

    max_all += max_value

    print(arg_list, max_value)

    arg_list = np.concatenate([arg_list[:max_idx], arg_list[max_idx+1:]])
    
print(max_all)