atcoder#ARC082B. [ABC072D] Derangement
[ABC072D] Derangement
Score : points
Problem Statement
You are given a permutation consisting of ,,..,. You can perform the following operation any number of times (possibly zero):
Operation: Swap two adjacent elements in the permutation.
You want to have for all . Find the minimum required number of operations to achieve this.
Constraints
- is a permutation of .
Input
The input is given from Standard Input in the following format:
..
Output
Print the minimum required number of operations
5
1 4 3 5 2
2
Swap and , then swap and . is now and satisfies the condition. This is the minimum possible number, so the answer is .
2
1 2
1
Swapping and satisfies the condition.
2
2 1
0
The condition is already satisfied initially.
9
1 2 4 9 5 8 7 3 6
3