//#include "grader.cpp"
//#include <bits/stdc++.h>
#ifdef EVAL
#define debug(x) (x)
#else
#define debug(x) ( cerr << "[" << __LINE__ << "] " << #x << " -> " << (x) << endl, (x) )
#endif

using namespace std; 

long long paletta_sort(int N, int V[]) {
	for (int i = 0; i<N; i++) {
		if (i%2== 0 && V[i]%2==1)
			return -1;
		else if (i%2==1 && V[i]%2==0 )
			return -1;
	}
	long long ris;
	int i = 0, j = 0, a;
	while (j<N) {
		if (V[j]==j) {
			j++;
		}
		if (i > N-2) 
			if (j > N-2) break; 
			else i = j;
		debug (j);
		debug (i);
		debug (V[i]);
		debug (V[i+2]);
		if (V[i]>V[i+2]) {
			a = V[i+2];
			V[i+2] = V[i];
			V[i] = a;
			ris++;
		}
		for (int z = 0; z<N; z++)
			debug(V[z]);
		i++;
		
	}
    return ris;
}
