Reduce the array
Medium
Execution time limit is 1 second
Runtime memory usage limit is 1,228 megabytes
Given an array of integers and an integer . Find the minimum cost to reduce the array to a single element. You can perform the following operation any number of times:
Choose any pair of consecutive elements and , and replace them with . The cost of this operation is .
Input
The first line contains two integer and . The second line contains integers .
Output
Print the minimum cost to reduce the array to a single element.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 21
Acceptance rate 100%