CF BUDDY
← Problems·

1965A · Everything Nim

1400 · games, greedy, math

Problem: Alice and Bob are playing a game on nn piles of stones. On each player's turn, they select a positive integer kk that is at most the size of the smallest nonempty pile and remove kk stones from each nonempty pile at once. The first player who is unable to make a move (because all piles are empty) loses.

Given that Alice goes first, who will win the game if both players play optimally?

Input Format: The first line of the input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2\cdot 10^5) — the number of piles in the game.

The next line of each test case contains nn integers a1,a2,ana_1, a_2, \ldots a_n (1ai1091 \le a_i \le 10^9), where aia_i is the initial number of stones in the ii-th pile.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot 10^5.

Output Format: For each test case, print a single line with the name of the winner, assuming both players play optimally. If Alice wins, print "Alice", otherwise print "Bob" (without quotes).

Note: In the first test case, Alice can win by choosing k=3k=3 on her first turn, which will empty all of the piles at once.

In the second test case, Alice must choose k=1k=1 on her first turn since there is a pile of size 11, so Bob can win on the next turn by choosing k=6k=6.

Sample Cases

Case 1

Input

7
5
3 3 3 3 3
2
1 7
7
1 3 9 7 4 2 100
3
1 2 3
6
2 1 3 4 2 4
8
5 7 2 9 6 3 3 2
1
1000000000

Output

Alice
Bob
Alice
Alice
Bob
Alice
Alice

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback