fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7.  
  8. while (t--) {
  9. int n, x = 0, y = 0;
  10. cin >> n;
  11.  
  12. for (int i = 0; i < n; ++i) {
  13. int a;
  14. cin >> a;
  15. if (i & 1)
  16. x += (i ^ a) & 1;
  17. else
  18. y += (i ^ a) & 1;
  19. }
  20.  
  21. if (x != y)
  22. cout << -1 << "\n";
  23. else
  24. cout << x << "\n";
  25. }
  26.  
  27. return 0;
  28. }
  29.  
  30.  
Success #stdin #stdout 0.01s 5304KB
stdin
4
4
3 2 7 6
3
3 2 6
1
7
7
4 9 2 1 18 3 0
stdout
2
1
-1
0