import math
import itertools

N = int(input())
A_map = map(int, input().split())
A = list(A_map)
NUM = [0]*N
for i in range(N):
    NUM[i] = i
a = list(itertools.permutations(A,N))
num = list(itertools.permutations(NUM,N))
ureshisa = 0
ureshisa_max = 0

for aa, nnum, i in zip(a, num ,range(len(a))):
    #print(aa)
    #print(nnum)
    #print(i)
    ureshisa = 0
    for j in range(N):
        ureshisa = ureshisa + aa[j]*abs(j-nnum[j])
    if ureshisa >= ureshisa_max:
        ureshisa_max = ureshisa
print(ureshisa_max)
#for i in range(len(a)):
#    for j in range(N):
