#T653. 序列修改

序列修改

Description

Given a sequence {A1,A2,...,ANA_1, A_2, ..., A_N}, modify the minimum number of elements such that the sequence {ANA_N} becomes an arithmetic sequence with a common difference of 1.

Input Format

Line 1: An integer N.
Line 2: N integers A1,A2,...,ANA_1, A_2, ..., A_N.

Output Format

An integer representing the minimum number of elements to be modified.

3
2 1 4
1

Hint

【Data Range and Constraints】

For 40% of the data, n<=1000n <= 1000;

For 100% of the data, n<=105n <= 10^5, 1<=Ai<=1061 <= A_i <= 10^6.

Source

CodesOnline