{"id":"9b79916c-86cf-43c1-8d1c-2e4985d6c2db","name":"Grundy Number","description":"Two players Alice and Bob are playing a game. They have a pile with n coins in it.\r\nThey can pick only allowed numbers of coins 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 integer n(no. of coins in the pile).\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;= n &lt;= 1000","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 coins, 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 coins = 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(coins, picks);\r\n }\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"8\r\n3\r\n5\r\n1\r\n4","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":"829c7664-a55b-43f9-b3b2-28979b10a9d1","name":"Grundy Number","slug":"grundy-number","type":1}],"next":{"id":"0998f30a-29e2-4ecc-9b55-8f05baff7c97","name":"Deleting Divisors","type":1,"slug":"deleting-divisors"},"prev":{"id":"04426e62-ffd2-4e4e-a5be-61b9764ec188","name":"Palindrome Game (hard Version)","type":1,"slug":"palindrome-game-hard-version"}}}

Grundy Number

Two players Alice and Bob are playing a game. They have a pile with n coins in it. They can pick only allowed numbers of coins 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":"9b79916c-86cf-43c1-8d1c-2e4985d6c2db","name":"Grundy Number","description":"Two players Alice and Bob are playing a game. They have a pile with n coins in it.\r\nThey can pick only allowed numbers of coins 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 integer n(no. of coins in the pile).\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;= n &lt;= 1000","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 coins, 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 coins = 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(coins, picks);\r\n }\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"8\r\n3\r\n5\r\n1\r\n4","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":"829c7664-a55b-43f9-b3b2-28979b10a9d1","name":"Grundy Number","slug":"grundy-number","type":1}],"next":{"id":"0998f30a-29e2-4ecc-9b55-8f05baff7c97","name":"Deleting Divisors","type":1,"slug":"deleting-divisors"},"prev":{"id":"04426e62-ffd2-4e4e-a5be-61b9764ec188","name":"Palindrome Game (hard Version)","type":1,"slug":"palindrome-game-hard-version"}}}
plane

Editor


Loading...

Grundy Number

medium

Two players Alice and Bob are playing a game. They have a pile with n coins in it. They can pick only allowed numbers of coins 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<= n <= 1000

Format

Input

The first line contains integer n(no. of coins in the pile). 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

8 3 5 1 4

Sample Output

BOB

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode