cswork / OAOpen practice workspace

WalmartOA #4

Minimum Possible Value of Function

Estimated MediumJudge-ready

Topics (AI-labelled)Bits & MathIn-place Arrays

Given a sequence X, find an integer k that minimizes Σ|X[i]−(k+i+1)|, and output the minimum value.

The standard input/output format and any supplementary ranges on this site are as stated in this problem.

Input

n (1≤n≤200000), and the next line has n integers X[i] (1≤X[i]≤10^9).

Output

Output the minimum value of the function as an integer.

Example 1

Input:

5
2 2 3 5 5

Output:

2

Example 2

Input:

1
1

Output:

0

Example 3

Input:

3
10 1 10

Output:

10

Editorial

Loading solution…