from collections import deque


class Move:
    def __init__(self, rems, left, right, joy):
        self.rems = rems
        self.left = left
        self.right = right
        self.joy = joy


n = int(input())
a = list(map(int, input().split()))

moves = deque([Move(set(range(n)), 0, n - 1, 0)])
max_joy = 0

while moves:
    move = moves.pop()
    
    if not move.rems:
        if move.joy > max_joy:
             max_joy = move.joy
             continue
    
    max_add_joy = 0
    max_moves = []
    
    for rem in move.rems:
        left_dist = abs(move.left - rem)
        right_dist = abs(move.right - rem)
        
        if left_dist >= right_dist:
            add_joy = a[rem] * left_dist
            
            if add_joy > max_add_joy:
                max_add_joy = add_joy
                max_moves = [(rem, 'l')]
            elif add_joy == max_add_joy:
                max_moves.append((rem, 'l'))
        
        if left_dist <= right_dist:
            add_joy = a[rem] * right_dist
            
            if add_joy > max_add_joy:
                max_add_joy = add_joy
                max_moves = [(rem, 'r')]
            elif add_joy == max_add_joy:
                max_moves.append((rem, 'r'))
        
        for max_move in max_moves:
            child_rem = set(move.rems)
            child_rem.remove(max_move[0])
            
            child_left = move.left
            child_right = move.right
            if max_move[1] == 'l':
                child_left += 1
            else:
                child_right -= 1
            
            moves.append(Move(child_rem, child_left, child_right, move.joy + max_add_joy))

print(max_joy)
