# -*- coding: utf-8 -*-
import itertools
# 整数の入力
n = int(input())
before = list(map(int, input().split()))
li = []
for i in range(n):
    li.append(i)
# 計算
after = list(itertools.permutations(li)) # 順列を生成
ans = 0
for t in after:
    temp = 0
    for i in range(n):
        temp += abs(t[i]-i)*before[i]
    # print(t, temp)
    if ans < temp:
        ans = temp
print(ans)