N = int(input())
A = list(map(int, input().split()))
ans = 0

def get_score(N, A, fixed_, i_, score_):
    global ans
    score = score_
    i = i_
    fixed = fixed_[:]
    self = A[i]
    for x in range(i,N):
        if x in fixed_:
            continue
        elt = A[x]
        fixed += x, i,
        score += (elt + self) * abs(i-x)
        while i in fixed:
            i += 1
        if i < N:
            get_score(N, A, fixed, i, score)
        else:
            ans = max(ans, score)
        fixed = fixed_[:]
        i = i_
        score = score_
        
        
        
get_score(N, A, [], 0, 0)
print(ans)
        
