For an array of numbers, we define its weight as , where .
Sux receives an array of elements as a gift from his grandfather. One day, he goes on a mountain trip with his friends. Being very attached to the gift, he decides to take the array with him. Upon reaching the base of the mountain, he realizes with sadness that he cannot carry the array alone to the top because it is too heavy. Therefore, Sux tries to divide the array into disjoint and non-empty subarrays so that each of his friends receives exactly one subarray (leaving Sux with exactly one) and the sum of the cumulative weights is minimized.
Task
Help Sux calculate the minimum value.
Input data
The first line of the input contains three integers, , , and . The second line contains numbers separated by spaces.
Output data
The first line contains a number representing the answer to the problem.
Constraints and clarifications
- If Sux divides the array into subarrays: , then the cumulative weight is .
- The legend says that even now, the tests for joingraf are not ready.
# | Score | Constraints |
---|---|---|
1 | 10 | |
2 | 30 | |
3 | 10 | |
4 | 50 |
Example 1
stdin
6 2 9
2 6 7 1 8 7
stdout
62
Explanation
If we choose to split the array into subarrays and then the total weight will be .
However, if we split the array into subarrays and , we get a total weight of .
Example 2
stdin
10 5 6
57258 79818 45081 80878 97780 67843 78314 38965 34431 9159
stdout
30