AdvancedRating 1800
Merge the Piles
Piles of stones stand in a row. Merging two neighbouring piles costs the total number of stones in them. Merge everything into one pile and print the least total cost.
Input
n (≤ 200), then n pile sizes.
Output
One integer.
Sample 1
Input
4 10 20 30 40
Output
190
Sample 2
Input
1 5
Output
0
Output appears here