Even Number Addicts (Codeforces 1738C)
Tags: Greedy, games

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: 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: For each test case, output "Alice" (without quotes) if Alice wins and "Bob" (without quotes) otherwise.

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.

Sample Inputs:
4
3
1 3 5
4
1 3 5 7
4
1 2 3 4
4
10 20 30 40

Sample Outputs:
Alice
Alice
Bob
Alice

Solution (Python):
t = int(input())
for _ in range(t):
    n = int(input())
    lis = list(map(int, input().split()))
    (odd_count, even_count) = (0, 0)
    for i in lis:
        if i % 2 != 0:
            odd_count += 1
        else:
            even_count += 1
    a = n // 2 + n % 2
    if odd_count % 4 == 0:
        print('Alice')
    elif odd_count % 4 == 1:
        if n % 2 == 0:
            print('Alice')
        else:
            print('Bob')
    elif odd_count % 4 == 2:
        print('Bob')
    else:
        print('Alice')

Solution (Python):
for _ in range(int(input())):
    n = int(input())
    p = sum([int(i) % 2 for i in input().split()])
    if n % 2:
        if p % 2:
            p = p // 2
            if p % 2:
                print(' Alice')
            else:
                print('Bob')
        else:
            p = p // 2
            if p % 2 == 0:
                print(' Alice')
            else:
                print(' Bob')
    elif p % 2 == 0:
        p = p // 2
        if p % 2 == 0:
            print(' Alice')
        else:
            print(' Bob')
    else:
        print(' Alice')

Solution (Python):
def LM():
    return list(map(int, input().split()))

def MM():
    return map(int, input().split())

def M():
    return int(input())

def I():
    return input()

def solve():
    n = M()
    a = LM()
    co = sum(map(lambda x: x % 2, a))
    ce = sum(map(lambda x: x % 2 == 0, a))
    ans = 'Alice'
    if co % 4 == 2:
        ans = 'Bob'
    elif co % 4 == 1 and ce % 2 == 0:
        ans = 'Bob'
    print(ans)
    return
if __name__ == '__main__':
    t = 1
    t = M()
    while t > 0:
        t -= 1
        solve()