You are given an array A of n integers. Merging 2 adjacent elements Ai and Ai+1 costs Ai+Ai+1.
Perform the above operation until there is only 1 element left in A, what is the minimum cost?
Input:
4
10 20 30 40
Output:
190
The merging happens as follows (bolded elements are merged elements):