Puzzle multiplication#877

Puzzle multiplication

1 second
128 megabytes
Very easy

In the multiplication puzzle, you play with a number of cards, each containing one positive integer. During a turn, a player removes one card from the series and receives a number of points equal to the product of the number on the removed card and the numbers on the cards lying immediately to its left and right. It is not allowed to remove the first or last card. After the final move, only two cards remain in the series.

The goal of the game is to remove cards in such a manner as to minimize the total number of points.

For example, if the cards contain the numbers , , , , and , the player can take the card with the number , then , then , and obtain points:

10 \cdot 1 \cdot 50 + 50 \cdot 20 \cdot 5 + 10 \cdot 50 \cdot 5 = 500 + 5000 + 2500 = 8000

If the player removes the cards in reverse order, i.e., , then , then , the number of points would be:

1 \cdot 50 \cdot 20 + 1 \cdot 20 \cdot 5 + 10 \cdot 1 \cdot 5 = 1000 + 100 + 50 = 1150

Input

The first line contains the number of cards (3 \leq n \leq 100). The second line contains integers representing the numbers on the cards. The numbers on the cards are integers from to .

Output

Print a single integer — the minimum possible number of points.

Examples

Example 1

Loading
Loading