Building an Increasing Sequence

No attempts yetTime limit2sMemory limit512 MB

Problem

An integer sequence A1,A2,,ANA_1, A_2, \dots, A_N is given.

Among all integer sequences BB that satisfy B1<B2<<BNB_1 < B_2 < \dots < B_N, take one that makes B1A1+B2A2++BNAN|B_1 - A_1| + |B_2 - A_2| + \dots + |B_N - A_N| as small as possible and print that minimum value.

The sequences AA and BB consist of integers only, and every element of BB has to lie inside the range of a 32-bit integer type.

Input

The first line contains NN. (1N1061 \le N \le 10^6)

The second line contains the elements of AA in order, A1,A2,,ANA_1, A_2, \dots, A_N. (0Ai2×1090 \le A_i \le 2 \times 10^9)

Output

Print the smallest possible value of B1A1+B2A2++BNAN|B_1 - A_1| + |B_2 - A_2| + \dots + |B_N - A_N| on one line.

Hint

For A=(9,4,8,20,14,15,18)A = (9, 4, 8, 20, 14, 15, 18), the sequence B=(6,7,8,13,14,15,18)B = (6, 7, 8, 13, 14, 15, 18) minimizes the sum, and that minimum is 13.