A cheetah and a cheater are going to play the game of Nim. In this game they use N piles…
- User
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
-1instead.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.
Examples
Input
3 2 3 4
Output
3
Input
3 100 100 100
Output
-1
Assistant
pythondef main(): import sys input = sys.stdin.read().split() n = int(input[0]) a = list(map(int, input[1:n+1])) original_xor = 0 for num in a: original_xor ^= num if original_xor == 0: print(0) return m_set = set() for num in a: delta = num ^ (num - 1) m = (delta + 1).bit_length() - 1 m_set.add(m) current_xor = 0 count = 0 for j in reversed(range(61)): # Cover up to 60 bits target_bit = (original_xor >> j) & 1 current_bit = (current_xor >> j) & 1 if current_bit != target_bit: required_m = j + 1 if required_m in m_set: count += 1 mask = (1 << required_m) - 1 current_xor ^= mask else: print(-1) return print(count if current_xor == original_xor else -1) if __name__ == '__main__': main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.