CodeforcesMar 25, 2025

Swap Game

Hazrat Ali

Codeforces

Alice and Bob are playing a game on an array aa of nn positive integers. Alice and Bob make alternating moves with Alice going first.

In his/her turn, the player makes the following move:

  • If a1=0a1=0, the player loses the game, otherwise:
  • Player chooses some ii with 2in2≤i≤n. Then player decreases the value of a1a1 by 11 and swaps a1a1 with aiai.

Determine the winner of the game if both players play optimally.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1t2104)(1≤t≤2⋅104)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (2n105)(2≤n≤105)  — the length of the array aa.

The second line of each test case contains nn integers a1,a2ana1,a2…an (1ai109)(1≤ai≤109)  — the elements of the array aa.

It is guaranteed that sum of nn over all test cases does not exceed 21052⋅105.

Output

For each test case, if Alice will win the game, output "Alice". Otherwise, output "Bob".

You can output each letter in any case. For example, "alIcE", "Alice", "alice" will all be considered identical.

Example
Input
3
2
1 1
2
2 1
3
5 4 4

Output
Bob
Alice
Alice
Note

In the first testcase, in her turn, Alice can only choose i=2i=2, making the array equal [1,0][1,0]. Then Bob, in his turn, will also choose i=2i=2 and make the array equal [0,0][0,0]. As a1=0a1=0, Alice loses.

In the second testcase, once again, players can only choose i=2i=2. Then the array will change as follows: [2,1][1,1][1,0][0,0][2,1]→[1,1]→[1,0]→[0,0], and Bob loses.

In the third testcase, we can show that Alice has a winning strategy.

 

Solution : 

#include<stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int A[n];
        for(int i=0;i<n;i++)
        {
            scanf("%d",&A[i]);
        }
        if(A[0]==0)
            printf("Bob\n");
        else if(A[0]==1)
            printf("Bob\n");

        else
        {

            int min=A[0];
            for(int i=1;i<n;i++)
            {
            if(min>A[i])
                min=A[i];
            }

        if(min==A[0])
            printf("Bob\n");
        else
            printf("Alice\n");
        }

    }

}

 

 

Comments