NIKHIL AND BINARY NUMBERS

3.9

12 votes
Recursion, Dynamic Programming
Problem

Nikhil has written N binary integers (i.e. eithim zero or one) on a copy. He recently learned about XOR operation. Now He wants to erase exactly one integer in the array so that the XOR of the remaining N - 1 numbers is zero. Please help him to calculate the number of ways of doing so.

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of numbers that Nikhil has written on a blackboard. The second line contains N space-separated integers A1, A2, ..., AN denoting the numbers He had written.

Output

For each test case, output a single line containing the number of ways to erase exactly one integer so that the XOR of the remaining integers is zero. The ways when you erase the same integer but on different places in the given sequence are considered different.

Constraints

1 = T = 20 2 = N = 10^5 0 = Ai = 1

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Example case 1. If you erase the first number on the blackboard, then the XOR of the rest of numbers will be equal to zero. Example case 2. You can erase any of the given 5 numbers, it will make the XOR of the rest equal to zero.

Editor Image

?