`{"id":"0543a7e3-134b-4ae4-916a-826b93be1728","name":"A Modified Game Of Nim","description":"Given an array of integers, two players Alice and Bob are playing a game where Alice can remove any element from the array that are multiples of 3. Similarly, Bob can remove multiples of 5. The player who can't remove any element loses the game. The task is to find the winner of the game if Alice starts first and both play optimally.","inputFormat":"The first line contains integer n, no. of integers.\r\nsecond line contains n integers arr[1],arr[2]...arr[n].","outputFormat":"Print the winner (ALICE or BOB).","constraints":"1&lt;= n &lt;= 10^5\r\n1&lt;= arr[i] &lt;= 10^8","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class Main {\r\n static String getWinner(int arr[], int n) {\r\n\r\n }\r\n\r\n public static void main(String[] args) throws NumberFormatException, IOException {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int n = Integer.parseInt(br.readLine());\r\n int[] arr = new int[n];\r\n String[] st = br.readLine().split(\" \");\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = Integer.parseInt(st[i]);\r\n }\r\n\r\n System.out.println(getWinner(arr, n));\r\n }\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5\r\n15 6 9 10 20","sampleOutput":"ALICE\r\n","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":"e4f114f9-46b2-4ae6-a6e8-726cf566c0be","name":"A Modified Game Of Nim","slug":"a-modified-game-of-nim","type":1}],"next":{"id":"907e8e95-4e3d-42f0-a0f0-ed129a6f7864","name":"Winner In Nim Game","type":1,"slug":"winner-in-nim-game"},"prev":{"id":"e941671b-d9c9-4f0d-9edc-a70d0a68d5b4","name":"First Move In A Nim Game","type":1,"slug":"first-move-in-a-nim-game"}}}`

# A Modified Game Of Nim

Given an array of integers, two players Alice and Bob are playing a game where Alice can remove any element from the array that are multiples of 3. Similarly, Bob can remove multiples of 5. The player who can't remove any element loses the game. The task is to find the winner of the game if Alice starts first and both play optimally.

`{"id":"0543a7e3-134b-4ae4-916a-826b93be1728","name":"A Modified Game Of Nim","description":"Given an array of integers, two players Alice and Bob are playing a game where Alice can remove any element from the array that are multiples of 3. Similarly, Bob can remove multiples of 5. The player who can't remove any element loses the game. The task is to find the winner of the game if Alice starts first and both play optimally.","inputFormat":"The first line contains integer n, no. of integers.\r\nsecond line contains n integers arr[1],arr[2]...arr[n].","outputFormat":"Print the winner (ALICE or BOB).","constraints":"1&lt;= n &lt;= 10^5\r\n1&lt;= arr[i] &lt;= 10^8","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class Main {\r\n static String getWinner(int arr[], int n) {\r\n\r\n }\r\n\r\n public static void main(String[] args) throws NumberFormatException, IOException {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int n = Integer.parseInt(br.readLine());\r\n int[] arr = new int[n];\r\n String[] st = br.readLine().split(\" \");\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = Integer.parseInt(st[i]);\r\n }\r\n\r\n System.out.println(getWinner(arr, n));\r\n }\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5\r\n15 6 9 10 20","sampleOutput":"ALICE\r\n","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":"e4f114f9-46b2-4ae6-a6e8-726cf566c0be","name":"A Modified Game Of Nim","slug":"a-modified-game-of-nim","type":1}],"next":{"id":"907e8e95-4e3d-42f0-a0f0-ed129a6f7864","name":"Winner In Nim Game","type":1,"slug":"winner-in-nim-game"},"prev":{"id":"e941671b-d9c9-4f0d-9edc-a70d0a68d5b4","name":"First Move In A Nim Game","type":1,"slug":"first-move-in-a-nim-game"}}}`

Editor

# A Modified Game Of Nim

medium

Given an array of integers, two players Alice and Bob are playing a game where Alice can remove any element from the array that are multiples of 3. Similarly, Bob can remove multiples of 5. The player who can't remove any element loses the game. The task is to find the winner of the game if Alice starts first and both play optimally.

## Constraints

1<= n <= 10^5 1<= arr[i] <= 10^8

## Format

### Input

The first line contains integer n, no. of integers. second line contains n integers arr[1],arr[2]...arr[n].

### 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;}5 15 6 9 10 20```

### 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;}ALICE ```

Discussions

Show Discussion

Related Resources