AdvancedRating 1900
Pop the Balloons
Popping balloon i earns left × aᵢ × right, where left and right are the balloons currently next to it (a missing neighbour counts as 1). Pop all balloons in the best order and print the most coins.
Input
n (≤ 120), then n integers.
Output
One integer.
Sample 1
Input
4 3 1 5 8
Output
167
Sample 2
Input
2 1 5
Output
10
Output appears here