atcoder#ABC302G. [ABC302G] Sort from 1 to 4
[ABC302G] Sort from 1 to 4
Score : points
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 A_iA_j$.
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.
6
3 4 1 1 2 4
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.
4
2 3 4 1
3