Apteka

No attempts yetTime limit1sMemory limit512 MB

Problem

Jaś is standing at the very back of the queue in front of a pharmacy. Because Jaś is in a great hurry, he decides to try swapping places with some of the people ahead of him, even if he has to pay for it.

Every person is willing to swap, but the ii-th person must be paid cic_i for each single place they move further back in the queue. More precisely, if Jaś is kk places (k>0k > 0) further from the cashier than some person and wants to swap places with them, he must pay that person kcik \cdot c_i.

Jaś would like to be first in the queue. Determine how to make the swaps so that he spends as little as possible.

Input

The first line contains one integer nn (1n1061 \le n \le 10^6), the number of people standing in front of Jaś in the pharmacy queue.

The second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n (1ci1091 \le c_i \le 10^9), where cic_i is the amount Jaś must pay the ii-th person to move them one place further back in the queue. The people are numbered starting from the one Jaś directly stands behind, that is, from the back of the queue toward its front.

Output

Print a single integer: the minimum amount Jaś must pay to become first in the queue.

Hint

In the example, Jaś first swaps with the third person from the front for a cost of 222 \cdot 2, and then with the person at the front for a cost of 323 \cdot 2. The total cost is therefore 1010.