#K4186. Taco Stone Game Simulation

    ID: 26959 Type: Default 1000ms 256MiB

Taco Stone Game Simulation

Taco Stone Game Simulation

You are given an initial number \( n \) of stones in a pile. Two players take turns removing stones from the pile. In each turn, a player can remove either 1, 2, or 3 stones. The objective is to be the player who removes the last stone, thereby winning the game.

The game proceeds as follows:

  • If the current number of stones is a multiple of 4, the player removes 3 stones.
  • Otherwise, the player removes \( n \mod 4 \) stones, leaving a multiple of 4 for the opponent.

The moves are recorded as triples: (player, stones_removed, stones_remaining). After the last move, the winner is declared with the message "Player X wins!" where X is the number of the player who removed the last stone.

Note: The optimal strategy provided might not guarantee a win for both players if the starting count does not allow a forced win strategy. However, use this simulation strategy to generate the sequence of moves and the winning player.

inputFormat

The input consists of a single integer \( n \) (\( 1 \le n \le 10^9 \)) representing the initial number of stones in the pile.

The input is read from standard input (stdin).

outputFormat

Output the sequence of moves followed by the winner message. For each move, output one line in the format:

player stones_removed stones_remaining

After all moves, output the winner message on a new line (e.g., "Player 1 wins!"). The output is printed to standard output (stdout).

## sample
10
1 2 8

2 3 5 1 1 4 2 3 1 1 1 0 Player 1 wins!

</p>