In an orchard, D has already collected all the fruit and put them in different piles. Now D wants to combine all the fruit into one pile.
For each "combine" operation, D can combine two piles of fruit into one, using an amount of stamina equal to the total weight of the two piles. We can see that after
Find the minimum amount of stamina that D needs to combine all fruit into one pile.
Input Specification
The first line contains an integer
Output Specification
Output the minimum stamina D needs to combine all fruit into one pile.
Sample Input
Copy
3
1 2 9
Sample Output
Copy
15
Constraints
For
For
For
Comments