Cheap Tricks


The MAPS executives, the president, vice president, and treasurer, are coordinating an Olympic artistic gymnastics showcase after a workshop. To plan the balance beam routine, they place marks 0,1,…,n0, 1, \ldots, n along the beam. Mark 00 is the start, and mark nn is the finish.

For every destination mark ii with 1≤i≤n1 \leq i \leq n, the judges assign a landing coefficient cic_i.

A gymnast may move from any mark jj to any destination mark ii. The mark jj may be before or after ii, since a routine is allowed to change direction. Landing at ii costs:

∣j−i∣×ci|j-i| \times c_i

Find the minimum total cost needed to reach mark nn.

Input

The first line contains one integer nn (1≤n≤1061 \leq n \leq 10^6): the number of destination marks.

The second line contains nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n (1≤ci≤1091 \leq c_i \leq 10^9), where cic_i is the landing coefficient of mark ii.

Output

Print one integer: the minimum total cost.

Example 1

Input 1
3
5 4 5
Output 1
13

Example 2

Input 2
1
5
Output 2
5

Example 3

Input 3
4
1 1 1 1
Output 3
4

Example 4

Input 4
5
3 2 3 2 4
Output 4
12

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.