Buddy Nim
Three players Alice and Bob and Charlie are playing a game. There are two tables, on the first table, there are N heaps containing A[1],A[2].... A[n] coins, on the second table , there are M heaps containing B[1], B[2]... B[m] coins.Input Format
Initially, Alice is playing at the first table and Bob is playing at the second table. The players take their turns in this order: Charlie, Alice, Bob, Charlie, etc.
Bob and alice in their turn can remove as much coin as they want(min is 1) from any one pile of their respective tables. Whoever cannot remove any stone from a pile loses.
Charlie does not play at any table. Instead, on his turn, he decides if Alice and Bob should keep playing at their respective tables or swap places.
Alice and Charlie are buddies and they cooperate, playing in the optimal way that results in Alice's victory (if possible). Find out whether alice will win or bob.
The first line contains two space separated integers n and m.Output Format
The second line contains n space separated integers a[1],a[2]...a[n].
The third line contains m space separated integers b[1], b[2]....b[n].
Print the winner (ALICE or BOB).Question Video
1<= n,m <= 10^5Sample Input
1<= A[i] <= 10^8
1<= B[i] <= 10^8
6 7Sample Output
24 6 10 56 9 1
0 6 24 1 9 56 10
BOB

Asked in Companies

Related Topics
Video Solution
Code Solution
{ }
{ }
Run