An integer sequence A1,A2,…,AN is given.
Among all integer sequences B that satisfy B1<B2<⋯<BN, take one that makes ∣B1−A1∣+∣B2−A2∣+⋯+∣BN−AN∣ as small as possible and print that minimum value.
The sequences A and B consist of integers only, and every element of B has to lie inside the range of a 32-bit integer type.
The first line contains N. (1≤N≤106)
The second line contains the elements of A in order, A1,A2,…,AN. (0≤Ai≤2×109)
Print the smallest possible value of ∣B1−A1∣+∣B2−A2∣+⋯+∣BN−AN∣ on one line.
For A=(9,4,8,20,14,15,18), the sequence B=(6,7,8,13,14,15,18) minimizes the sum, and that minimum is 13.