- Time limit: 1.00 s
- Memory limit: 512 MB
Given an array of numbers, your task is to divide it into subarrays, each of which has a single element.
On each move, you may choose any subarray and split it into two subarrays. The cost of such a move is the sum of values in the chosen subarray.
What is the minimum total cost if you act optimally?
Input
The first input line has an integer : the array size. The array elements are numbered .
The second line has integers : the contents of the array.
Output
Print one integer: the minimum total cost.
Constraints
Example
Input:
5 2 7 3 2 5
Output:
43