atcoder#ARC082B. [ABC072D] Derangement

[ABC072D] Derangement

Score : 400400 points

Problem Statement

You are given a permutation p1,p2,...,pNp_1,p_2,...,p_N consisting of 11,22,..,NN. You can perform the following operation any number of times (possibly zero):

Operation: Swap two adjacent elements in the permutation.

You want to have piip_i \neq i for all 1iN1 \leq i \leq N. Find the minimum required number of operations to achieve this.

Constraints

  • 2N1052 \leq N \leq 10^5
  • p1,p2,..,pNp_1,p_2,..,p_N is a permutation of 1,2,..,N1,2,..,N.

Input

The input is given from Standard Input in the following format:

NN

p1p_1 p2p_2 .. pNp_N

Output

Print the minimum required number of operations

5
1 4 3 5 2
2

Swap 11 and 44, then swap 11 and 33. pp is now 4,3,1,5,24,3,1,5,2 and satisfies the condition. This is the minimum possible number, so the answer is 22.

2
1 2
1

Swapping 11 and 22 satisfies the condition.

2
2 1
0

The condition is already satisfied initially.

9
1 2 4 9 5 8 7 3 6
3