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


head = 0 
tail = N-1
for _ in range(N) :
    _max = -float('inf')
    at_head = True
    idx = -1
    
    for j in range(N) :
        if _max < abs(head-j)*active[j] :
            _max = abs(head-j)*active[j]
            idx = j
            at_head = True
        
        if _max < abs(tail-j)*active[j] :
            _max = abs(tail-j)*active[j]
            idx = j
            at_head = False
        
    active[idx] = -1
    ans += _max
    if at_head :
        head += 1
    else :
        tail -= 1

print(ans)