Минимальное количество ходов в C
You are given an array a[0 \ldots n-1]a[0…n−1] of length nn which consists of non-negative integers. Note that array indices start from zero.
An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all ii (0 \le i \le n - 10≤i≤n−1) the equality i \bmod 2 = a[i] \bmod 2imod2=a[i]mod2 holds, where x \bmod 2xmod2 is the remainder of dividing xx by 2.
For example, the arrays [0, 5, 2, 10,5,2,1] and [0, 17, 0, 30,17,0,3] are good, and the array [2, 4, 6, 72,4,6,7] is bad, because for i=1i=1, the parities of ii and a[i]a[i] are different: i \bmod 2 = 1 \bmod 2 = 1imod2=1mod2=1, but a[i] \bmod 2 = 4 \bmod 2 = 0a[i]mod2=4mod2=0.
In one move, you can take any two elements of the array and swap them (these elements are not necessarily adjacent).
Find the minimum number of moves in which you can make the array aa good, or say that this is not possible.
input
4
4
3 2 7 6
3
3 2 6
1
7
7
4 9 2 1 18 3 0
outout
2
1
-1
0
Nuzhat Farhan