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 LuaJIT (2.0.4) (judge verdict: Accepted)

local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max

local function getxor(x, y)
  local ret = 0
  local mul = 1
  while(0 < x or 0 < y) do
    if((x % 2) + (y % 2) == 1) then
      ret = ret + mul
    end
    x, y, mul = mfl(x / 2), mfl(y / 2), mul * 2
  end
  return ret
end

local n = io.read("*n")
local tot = 0
local cutpos = {}
for i = 1, 32 do cutpos[i] = false end
for i = 1, n do
  local a = io.read("*n")
  tot = getxor(tot, a)
  local pos = 1
  while a % 2 == 0 do
    pos = pos + 1
    a = mfl(a / 2)
  end
  cutpos[pos] = true
end
local tgt = {}
local isok = true
while 0 < tot do
  table.insert(tgt, tot % 2 == 1)
  tot = mfl(tot / 2)
end
local cnt = 0
for i = #tgt, 1, -1 do
  if tgt[i] then
    if cutpos[i] then
      cnt = cnt + 1
      for j = 1, i - 1 do
        tgt[j] = not tgt[j]
      end
    else
      isok = false
      break
    end
  end
end
print(isok and cnt or -1)