Reduce the array
Medium
Execution time limit is 1 second
Runtime memory usage limit is 1,228 megabytes
Given an array consisting 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 array elements and and replace them with at a cost of .
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 2
Acceptance rate 100%