Problem:
Score : 500 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

A cheetah and a cheater are going to play the game of Nim.
In this game they use N piles of stones.
Initially the i-th pile contains a_i stones.
The players take turns alternately, and the cheetah plays first.
In each turn, the player chooses one of the piles, and takes one or more stones from the pile.
The player who can't make a move loses.

However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah.
From each pile, the cheater takes zero or one stone and eats it before the game.
In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats.

Compute the number of stones the cheater will eat.
In case there is no way for the cheater to win the game even with the cheating, print -1 instead.

Constraints

1 ≤ N ≤ 10^5

2 ≤ a_i ≤ 10^9

Input

The input is given from Standard Input in the following format:

N
a_1
:
a_N

Output

Print the answer.

Sample Input 1

3
2
3
4

Sample Output 1

3

The only way for the cheater to win the game is to take stones from all piles and eat them.

Sample Input 2

3
100
100
100

Sample Output 2

-1

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

//値Aiを1減らしたとき, 全体のxorは「下位log2(Ai & (-Ai))ビット」反転する。
//各xについて, log2(Ai & (-Ai)) = xを満たすiの個数をcnt[x]に入れておく。
//すると以下の問題になる。
//・yの初期値が与えられる。
//・yの下位xビットを反転する操作を高々cnt[x]回できる
//・y=0にできるか？できるなら操作回数を最小化せよ。
//これはxが大きい順に処理すれば解ける。O(N)
//ちなみに, 同じ操作を2回するのは無駄なので, cnt[x]をcnt[x] % 2に置き換えても問題ない。

#include <iostream>
using namespace std;

int n;
int a[100000];
int cnt[100000];

int log2(int x) {
	int i;
	for (i = 0; (1 << i) < x; i++);
	return i;
}

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < n; i++) cnt[log2(a[i] & -a[i])]++;
	
	int x = 0;
	for (i = 0; i < n; i++) x ^= a[i];
	
	int ans = 0;
	for (i = 29; i >= 0; i--) {
		if ((x >> i) % 2 == 0) continue;
		if (cnt[i] == 0) { cout << -1 << endl; return 0; }
		ans++;
		
		//xの下位iビットを全て反転
		x = x ^ ((1 << i) - 1);
	}
	cout << ans << endl;
	return 0;
}