Back
Close

Marble Game Replay

Statement

 Goal

Replay: who won the marble game?
A group of N players finished the marble game. Find out which player was the winner.
You are given the sequence of dice rolled during the game.

The game rules
At the start, each player from 1 to N has a bag with 10 marbles.
On the table there are 5 marble parking holes - numbered from 1-5. A parking hole can hold max 1 marble.

Starting with player 1, players roll the dice (after each other in ascending order i.e. player 1, 2, ... player 1, 2 ...).

IF dice value is 6: the player removes 1 marble from the player's bag.
IF dice value is 1,2,3,4, or 5: the player transfers 1 marble from the player's bag into the corresponding parking hole IF that corresponding parking hole is empty. OTHERWISE, the player transfers the marble from the corresponding parking hole into the player's bag.

The player wins, if the player's bag contains no marbles after the turn.
Marbles in the parking holes belong to no player.
Input
Line 1: An integer N for how many players participated in the game
Line 2: Number of rolled dices during the game
Line 3: The sequence of dice values they rolled, separated by spaces
Output
Line 1 : the player who won the game
Constraints
2<=N<=9
1<=player<=N
1<=dice<=6
Example
Input
2
51
4 6 6 3 6 5 4 1 6 6 4 6 4 1 5 4 6 6 2 1 2 3 3 4 6 1 2 2 3 3 3 3 2 2 6 5 4 1 1 2 1 6 2 3 3 1 1 3 3 4 4
Output
1

Game modes
Fastest

Test cases
2 players (51 rolls) Test
Input
2 51 4 6 6 3 6 5 4 1 6 6 4 6 4 1 5 4 6 6 2 1 2 3 3 4 6 1 2 2 3 3 3 3 2 2 6 5 4 1 1 2 1 6 2 3 3 1 1 3 3 4 4
Output
1

2 players (84 rolls) Validator
Input
2 84 1 6 1 5 2 5 3 3 5 1 4 6 6 2 1 2 1 5 4 5 5 4 3 4 3 2 4 5 4 5 4 5 1 3 3 4 2 2 5 1 3 2 4 1 6 5 3 6 3 3 5 2 1 3 1 5 3 4 4 1 1 4 4 1 2 5 2 5 3 1 1 2 5 5 3 6 2 6 4 6 1 1 4 3
Output
2

3 players (76 rolls) Test
Input
3 76 1 3 6 3 1 2 6 6 6 3 1 3 3 4 6 2 4 3 5 5 5 4 2 5 6 5 5 1 2 3 3 4 3 1 1 2 6 5 5 3 1 3 1 2 4 1 5 1 2 4 1 5 6 6 5 1 2 6 5 2 4 5 4 1 3 6 2 5 2 5 3 5 4 5 2 2
Output
1

3 players (108 rolls) Validator
Input
3 108 5 1 3 3 1 2 4 2 2 5 5 6 3 2 2 2 1 6 1 1 2 6 3 2 1 4 6 1 1 3 5 2 3 1 5 3 2 3 5 4 5 3 2 6 2 5 6 1 1 5 4 3 3 2 5 3 2 4 5 2 1 2 3 5 3 5 1 6 1 3 6 1 2 4 1 1 4 2 6 4 4 4 1 4 1 2 5 1 3 6 2 4 3 6 5 5 5 4 3 4 1 3 3 1 2 4 5 1
Output
3

5 players (100 rolls) Test
Input
5 100 4 6 6 6 6 3 4 1 1 2 6 2 6 5 4 2 2 2 1 6 4 6 6 6 1 3 3 1 3 3 6 4 2 6 3 3 5 3 4 5 3 1 1 5 5 4 5 1 2 6 3 1 2 3 5 2 5 1 4 1 3 6 1 3 3 3 3 1 3 3 2 5 1 3 2 3 5 4 2 1 3 2 6 6 2 6 4 1 1 2 1 4 2 4 2 4 4 3 4 5
Output
5

5 players (209 rolls) Validator
Input
5 209 6 6 6 5 5 5 6 3 5 4 4 1 3 3 4 4 6 2 5 2 4 3 5 5 5 3 3 4 4 4 2 4 2 2 4 1 5 5 3 4 5 4 6 4 5 2 2 2 1 6 6 1 5 3 5 4 1 6 2 5 6 1 3 5 1 4 3 2 4 3 6 4 6 2 5 4 6 6 5 3 2 5 4 6 4 2 4 3 2 3 5 3 6 2 4 6 1 6 2 6 5 3 1 6 2 2 4 3 4 2 5 4 2 2 5 3 1 5 3 6 1 4 1 3 4 6 2 4 3 6 1 1 4 3 4 3 1 6 3 2 3 5 4 5 3 5 3 1 3 3 5 4 2 1 6 3 6 4 3 5 2 2 2 2 4 3 4 3 2 4 4 3 5 1 1 2 5 3 2 6 3 2 2 5 1 5 2 4 1 5 1 5 2 3 5 2 5 5 1 1 1 6 5 6 5 1 2 2 2
Output
4

9 players (213 rolls) Test
Input
9 213 5 4 4 4 3 5 1 5 3 3 6 4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1 6 5 5 3 1 1 5 3 4 3 5 5 3 5 3 1 1 5 6 5 3 6 3 2 4 1 5 5 1 6 2 4 6 5 2 1 4 3 3 6 6 1 4 6 1 3 6 3 5 5 5 5 6 5 4 4 2 4 6 6 6 6 2 5 2 4 6 2 4 3 1 2 5 1 6 4 6 6 6 5 2 5 3 3 6 1 6 3 1 3 6 5 6 5 3 6 1
Output
1

Solution language

Solution

Stub generator input