408780: GYM103316 G Circus Mayhem

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Circus Mayhemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Mei and Kylie are bored at the circus, and decided they wanted to play with fire while Azuko was gone. There are $$$n$$$ flames currently in a line, and each flame has a size $$$s_i$$$. Mei and Kylie want to combine all the flames into 1, but since they aren't fire-benders, it costs a certain amount of energy to merge flames. Given two flames next to each other in line $$$s_i$$$ and $$$s_j$$$, it costs $$$s_i + s_j$$$ to merge the two flames, and then it is replaced with a flame that is $$$s_i + s_j$$$ in size at the same place in line.

Given $$$n$$$ flames and their sizes, determine the minimum cost to merge all the flames!

Input

The first line will contain $$$n$$$ $$$(1 \le n \le 200)$$$, the total number of flames.

The next line will each contain $$$n$$$ integers $$$s_i$$$ $$$(1 \le s_i \le 10^5)$$$, the size of the $$$i^{th}$$$ flame.

Output

A single integer detailing the minimum cost to merge all the flames together into one big flame.

ExamplesInput
3
1 4 5
Output
15
Input
2
10 9
Output
19

加入题单

算法标签: