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 (Clang 3.8.0) (judge verdict: Accepted)

int check[30];

int main() {

  for (int bit = 29; bit >= 0; bit--) {
    check[bit] = 0;
  }

  int n;
  scanf("%d", &n);
  int xor_sum = 0;
  int a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    xor_sum ^= a;
    a = a ^ (a - 1);

    switch (a) {
    case 1073741823:
      check[29] = 1;
      break;
    case 536870911:
      check[28] = 1;
      break;
    case 268435455:
      check[27] = 1;
      break;
    case 134217727:
      check[26] = 1;
      break;
    case 67108863:
      check[25] = 1;
      break;
    case 33554431:
      check[24] = 1;
      break;
    case 16777215:
      check[23] = 1;
      break;
    case 8388607:
      check[22] = 1;
      break;
    case 4194303:
      check[21] = 1;
      break;
    case 2097151:
      check[20] = 1;
      break;
    case 1048575:
      check[19] = 1;
      break;
    case 524287:
      check[18] = 1;
      break;
    case 262143:
      check[17] = 1;
      break;
    case 131071:
      check[16] = 1;
      break;
    case 65535:
      check[15] = 1;
      break;
    case 32767:
      check[14] = 1;
      break;
    case 16383:
      check[13] = 1;
      break;
    case 8191:
      check[12] = 1;
      break;
    case 4095:
      check[11] = 1;
      break;
    case 2047:
      check[10] = 1;
      break;
    case 1023:
      check[9] = 1;
      break;
    case 511:
      check[8] = 1;
      break;
    case 255:
      check[7] = 1;
      break;
    case 127:
      check[6] = 1;
      break;
    case 63:
      check[5] = 1;
      break;
    case 31:
      check[4] = 1;
      break;
    case 15:
      check[3] = 1;
      break;
    case 7:
      check[2] = 1;
      break;
    case 3:
      check[1] = 1;
      break;
    case 1:
      check[0] = 1;
      break;
    }
  }

  int ans = 0;
  for (int bit = 29; bit >= 0; bit--) {
    if (((1 << bit) & xor_sum) == 0) {
      continue;
    }
    int x = (1 << (bit + 1)) - 1;

    if (check[bit] > 0) {
      xor_sum ^= x;
      ans += 1;
    }
  }

  if (xor_sum != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}