Minimum increments#9023

Minimum increments

3 seconds
128 megabytes
Very easy

An array of positive integers is given. Find the minimum number of operations required to transform the array into an arithmetic progression with a difference of .

In one operation, you are allowed to increase any element of the array by .

Input

The first line contains a single integer n~(n \le 10^6).

The second line contains positive integers, each not exceeding 10^6.

Output

Print the minimum number of operations required to transform the array into an arithmetic progression with a difference of .

Examples

In the first test, the array should be transformed into:

8~9~10~11~12

To do this, we need

(8 - 3) + (9 - 6) + (10 - 4) + (11 - 11) + (12 - 5) = 5 + 3 + 6 + 0 + 7 = 21

operations.

Example 1

Loading
Loading

Example 2

Loading
Loading