As exams are starting soon, you plan to buy books from the book store. There, you find out a particular shelf of books pretty interesting and therefore you plan to buy the whole shelf (row) for yourself. However this a special book store and there is a special rule for buying books.
You are given an array of integers representing the cost of the books. For buying a particular book you will need to pay an amount equal to the product of {cost of that book * cost of immediate left book * cost of immediate right book}. After this that book comes out of the shelf and now the immediate left and right books become adjacent.
However as you don’t have much time left for the exams you are going to pick books in any random order. To prepare for the worst outcomes calculate the maximum amount of money you will need if you take out books in a hurry and don’t really care for the cost.
Note: Here you may assume that the immediate left neighbour of the leftmost book has a cost value of 1 and the immediate right neighbour of the rightmost book has a cost value of 1.
Input Format
First line of input contains an integer N denoting the size of the book shelf. The second line contains N integers denoting the cost of the books.
Constraints
N<=500
0<=Cost of the books<=2000
Output Format
Print on a single line the maximum amount of money you will need to pay.
Sample Input
4
3 1 5 8
Sample Output
167
Explanation
The shelf looks like [3, 1, 5, 8]
We will buy book 2, hence the cost will be 3 * 1 * 5=15
The shelf looks like [3, 5, 8]
We will buy book 2, hence the cost will be 3 * 5 * 8=120
The shelf looks like [3, 8]
We will buy book 1, hence the cost will be 1 * 3 * 8=24
The shelf looks like [8]
We will buy book 1, hence the cost will be 1 * 8 * 1=8
The shelf looks like [ ]
Therefore our total cost is 15+120+24+8=167
Here if we pick out books in any other order, it is guaranteed that the answer will be <=167. Hence our final answer is 167.