`{"id":"34ee3cf9-c9e3-4ca0-a00b-a779d276083b","name":"Two Pile With Grundy Number","description":"Two players Alice and Bob are playing a game. They have 2 pile's with n1 and n2 coins in it.\r\nThey can pick only allowed numbers of coins from any one pile at a time given in an array picks.\r\nAlice goes first and they take alternate turns.\r\nThe player who picks the last coin is the winner. Can you find out the winner.","inputFormat":"The first line contains two integers n1 and n2.\r\nSecond line contains size of picks array say l\r\npicks[0]\r\npicks[1]\r\n....\r\npicks[l-1]","outputFormat":"Print the winner (ALICE or BOB).","constraints":"1 &lt;= n1, n2 &lt;= 50","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n static void solve(int n1, int n2, int picks[]) {\r\n // print the winner here\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n Scanner scn = new Scanner(System.in);\r\n\r\n int n1 = scn.nextInt();\r\n int n2 = scn.nextInt();\r\n int l = scn.nextInt();\r\n int picks[] = new int[l];\r\n\r\n for (int i = 0; i < l; i++) {\r\n picks[i] = scn.nextInt();\r\n }\r\n\r\n solve(n1, n2, picks);\r\n }\r\n}\r\n\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4 3\r\n3\r\n1\r\n4\r\n2\r\n","sampleOutput":"BOB","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"1191e2be-22c8-444b-988f-201dc78b143e","name":"Game Theory For Experts","slug":"game-theory-for-experts-930","type":0},{"id":"0d8668cb-743f-46d1-94b2-8922f08c0b92","name":"Two Pile With Grundy Number","slug":"two-pile-with-grundy-number","type":1}],"next":null,"prev":{"id":"0998f30a-29e2-4ecc-9b55-8f05baff7c97","name":"Deleting Divisors","type":1,"slug":"deleting-divisors"}}}`

Two Pile With Grundy Number

Two players Alice and Bob are playing a game. They have 2 pile's with n1 and n2 coins in it. They can pick only allowed numbers of coins from any one pile at a time given in an array picks. Alice goes first and they take alternate turns. The player who picks the last coin is the winner. Can you find out the winner.

`{"id":"34ee3cf9-c9e3-4ca0-a00b-a779d276083b","name":"Two Pile With Grundy Number","description":"Two players Alice and Bob are playing a game. They have 2 pile's with n1 and n2 coins in it.\r\nThey can pick only allowed numbers of coins from any one pile at a time given in an array picks.\r\nAlice goes first and they take alternate turns.\r\nThe player who picks the last coin is the winner. Can you find out the winner.","inputFormat":"The first line contains two integers n1 and n2.\r\nSecond line contains size of picks array say l\r\npicks[0]\r\npicks[1]\r\n....\r\npicks[l-1]","outputFormat":"Print the winner (ALICE or BOB).","constraints":"1 &lt;= n1, n2 &lt;= 50","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n static void solve(int n1, int n2, int picks[]) {\r\n // print the winner here\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n Scanner scn = new Scanner(System.in);\r\n\r\n int n1 = scn.nextInt();\r\n int n2 = scn.nextInt();\r\n int l = scn.nextInt();\r\n int picks[] = new int[l];\r\n\r\n for (int i = 0; i < l; i++) {\r\n picks[i] = scn.nextInt();\r\n }\r\n\r\n solve(n1, n2, picks);\r\n }\r\n}\r\n\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4 3\r\n3\r\n1\r\n4\r\n2\r\n","sampleOutput":"BOB","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"1191e2be-22c8-444b-988f-201dc78b143e","name":"Game Theory For Experts","slug":"game-theory-for-experts-930","type":0},{"id":"0d8668cb-743f-46d1-94b2-8922f08c0b92","name":"Two Pile With Grundy Number","slug":"two-pile-with-grundy-number","type":1}],"next":null,"prev":{"id":"0998f30a-29e2-4ecc-9b55-8f05baff7c97","name":"Deleting Divisors","type":1,"slug":"deleting-divisors"}}}`

Editor

Two Pile With Grundy Number

medium

Two players Alice and Bob are playing a game. They have 2 pile's with n1 and n2 coins in it. They can pick only allowed numbers of coins from any one pile at a time given in an array picks. Alice goes first and they take alternate turns. The player who picks the last coin is the winner. Can you find out the winner.

Constraints

1 <= n1, n2 <= 50

Format

Input

The first line contains two integers n1 and n2. Second line contains size of picks array say l picks[0] picks[1] .... picks[l-1]

Output

Print the winner (ALICE or BOB).

Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 3 3 1 4 2 ```

Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}BOB`

Discussions

Show Discussion

Related Resources