Time limit
2s
Memory limit
128 MB
Let A[0], A[1], ..., A[N-1] be a permutation containing every integer from 0 to N-1 exactly once. From A, define a child array B of the same length as follows.
If the child array B produced by this process is also a permutation containing every integer from 0 to N-1 exactly once, then A is called a perfect permutation.
The following table shows every permutation A of length 3 and its child array B. The permutations {1, 2, 0} and {2, 0, 1} are perfect permutations because their child arrays are also permutations.
| A | B |
|---|---|
| 0, 1, 2 | 0, 0, 0 |
| 0, 2, 1 | 0, 0, 0 |
| 1, 0, 2 | 0, 1, 0 |
| 1, 2, 0 | 0, 1, 2 |
| 2, 0, 1 | 0, 2, 1 |
| 2, 1, 0 | 0, 2, 0 |
You are given a permutation P of length N. Find a perfect permutation Q whose difference from P is as small as possible. The difference between two permutations P and Q is the number of indices i such that P[i] and Q[i] are different.
The first line contains the size N of permutation P (1 <= N <= 50). The second line contains permutation P, which includes every integer from 0 to N-1 exactly once.
Print the minimum possible difference between the given permutation P and a perfect permutation Q.