Even Number Addicts
Contest: Codeforces Global Round 22
Difficulty rating: 1500
Tags: dp, games, greedy, math

Alice and Bob are playing a game on a sequence $$$a_1, a_2, \dots, a_n$$$ of length $$$n$$$. They move in turns and Alice moves first.

In the turn of each player, he or she should select an integer and remove it from the sequence. The game ends when there is no integer left in the sequence.

Alice wins if the sum of her selected integers is even; otherwise, Bob wins.

Your task is to determine who will win the game, if both players play optimally.

Input format:
Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The following lines contain the description of each test case.

The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$), indicating the length of the sequence.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \leq a_i \leq 10^9$$$), indicating the elements of the sequence.

Output format:
For each test case, output "Alice" (without quotes) if Alice wins and "Bob" (without quotes) otherwise.

Constraints:
Time limit: 2.0 s
Memory limit: 512.0 MB

Note:
In the first and second test cases, Alice always selects two odd numbers, so the sum of her selected numbers is always even. Therefore, Alice always wins.

In the third test case, Bob has a winning strategy that he always selects a number with the same parity as Alice selects in her last turn. Therefore, Bob always wins.

In the fourth test case, Alice always selects two even numbers, so the sum of her selected numbers is always even. Therefore, Alice always wins.

Example input:
4
3
1 3 5
4
1 3 5 7
4
1 2 3 4
4
10 20 30 40

Example output:
Alice
Alice
Bob
Alice

Editorial:
We only need to consider the case that $$$a_i =$$$ 0 or 1.
Suppose there are $$$a$$$ 0's and $$$b$$$ 1's in total. Consider the following cases:
• $$$b \equiv 2 \pmod 4$$$. Bob has a winning strategy: Always choose the number that Alice chooses in her last move. This strategy keeps the invariant that Alice and Bob have the same number of 1's after Bob's each move. The only exception that Bob cannot go on with this strategy is that Alice takes the last 0. In this case, there must be an even number of 1's (and no 0's) remaining. Therefore, each of Alice and Bob will choose half of the remaining 1's. At last, Alice and Bob have the same number $$$b/2$$$ of 1's, which is odd.
• $$$b \equiv 3 \pmod 4$$$. Alice has a winning strategy: Choose 1 first. After this move, the game is reduced to $$$a$$$ 0's and $$$b-1$$$ 1's with Bob taking the first turn and Bob wins if he has an even number of 1's at last. This reduced game is indeed the case of $$$b \equiv 2 \pmod 4$$$ which we have already proved that Bob always loses.
• $$$b \equiv 0 \pmod 4$$$. Alice has a winning strategy: Choose 0 first; after that, choose the number that Bob chooses in his last move. This strategy keeps the invariant that Alice and Bob have the same number of 1's after Alice's each move. The only exception that Alice cannot go on with this strategy is that there is no 0. In this case, there must be an even number of 1's (and no 0's) remaining. Therefore, each of Alice and Bob will choose half of the remaining 1's. At last, Alice and Bob have the same number $$$b/2$$$ of 1's, which is even.
• $$$b \equiv 1 \pmod 4$$$. If any of Alice and Bob chooses the first 1, the game is reduced to $$$a$$$ 0's and $$$b-1$$$ 1's with its opponent moving first, resulting in the case of $$$b \equiv 0 \pmod 4$$$ and its opponent wins. Therefore, the one who chooses the first 1 loses. With this observation, Alice will lose if there are an even number of $$$0$$$'s, i.e., $$$a \equiv 0 \pmod 2$$$; and Alice will win if $$$a \equiv 1 \pmod 2$$$.