#abc302g. [abc302_g]Sort from 1 to 4
[abc302_g]Sort from 1 to 4
Problem Statement
You are given a sequence of length , consisting of integers between and .
Takahashi may perform the following operation any number of times (possibly zero):
- choose a pair of integer such that , and swap and .
Find the minimum number of operations required to make non-decreasing.
A sequence is said to be non-decreasing if and only if for all .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the minimum number of operations required to make non-decreasing in a single line.
Sample Input 1
6
3 4 1 1 2 4
Sample Output 1
3
One can make non-decreasing with the following three operations:
- Choose to swap and , making .
- Choose to swap and , making .
- Choose to swap and , making .
This is the minimum number of operations because it is impossible to make non-decreasing with two or fewer operations.
Thus, should be printed.
Sample Input 2
4
2 3 4 1
Sample Output 2
3