#d2558. 快快变大
快快变大
Growing Fast
Problem Description
You are given an array of length . Then operations are performed. Each time, choose an index and merge and into , and you gain points.
So after each operation the length of the array decreases by ; the operations stop when only one element remains. Output the maximum total score you can finally obtain.
Input Format
The first line contains an integer .
The next line contains integers .
Output Format
One number, the answer.
Sample Input
3
1 2 3
Sample Output
26
Constraints
For all data, , .