Problem1278--Multiplication games

1278: Multiplication games

[Creator : ]
Time Limit : 1 sec  Memory Limit : 128 MB

Description

Multiplication games are performed on a single line of cards. Each card includes a positive integer. In each move, the player takes out a card, and the score is multiplied by its number on the left and right, so it is not allowed to take the last 1 cards of the 1th slides.
    After the last move, there are only two cards left.
    Your goal is to make the score and the smallest.
    For example, if the number is 10 1 50 20 5, take 1, 20, 50 in turn, and the total score is 10*1*50+50*20*5+10*50*5=8000 And take 50, 20, 1, the total score is 1*50*20+1*20*5+10*1*5=1150.

Input

The first line includes the number of cards (3<=n<=100);

the second line consists of n 1-100 integers, separated by spaces.

Output

Just one line: an integer of minimum score.

Sample Input Copy

6
10 1 50 50 20 5

Sample Output Copy

3650

Source/Category

JoyOI