N = int(input())
AA = list(map(int,input().split()))
AAwIdx = [[0]*2 for _ in range(N)]
for i in range(N):
    AAwIdx[i][0] = i
    AAwIdx[i][1] = AA[i]
AA_sorted = sorted(AAwIdx, key=lambda x: x[1], reverse=True)
#print(AA_sorted)

ans_all = 0
for i in range(2**(int(N/2))):
    AAs = format(i, 'b')
    Idx_i = 0
    Idx_f = N-1
    AnsIdx = [0]*N
    #print(Idx_f)
    answer = 0
    for i in range(N):
        if i>len(AAs)-1:
            if Idx_f - AA_sorted[i][0] > AA_sorted[i][0] - Idx_i:
                answer += abs(AA_sorted[i][0]-Idx_f)*AA_sorted[i][1]
                Idx_f -= 1
            else:
                answer += abs(AA_sorted[i][0]-Idx_i)*AA_sorted[i][1]
                Idx_i += 1

        elif AAs[i] == '1':
        #if Idx_f - AA_sorted[i][0] > AA_sorted[i][0] - Idx_i:
            answer += abs(AA_sorted[i][0]-Idx_f)*AA_sorted[i][1]
            Idx_f -= 1
        else:
            answer += abs(AA_sorted[i][0]-Idx_i)*AA_sorted[i][1]
            Idx_i += 1
    #print(answer)
    ans_all = max(answer, ans_all)
#    print(AAs)
#print(AnsIdx)
print((ans_all))