#P11429. Paradox Card Game

    ID: 13507 Type: Default 1000ms 256MiB

Paradox Card Game

Paradox Card Game

Five players, Igor, Lea, Marino, Sonja, Viktor, are seated in clockwise order around a circular table (in the order: Igor, Lea, Marino, Sonja, Viktor when viewed in clockwise direction). They play a card game for n rounds.

Each round, every player plays exactly one card. At the beginning of the game every player has cards numbered from 1 to n (each card is not colored initially). When playing a card, the player chooses one of the numbers available in his hand and paints it with one of the colors: red, blue, yellow, or green. A combination of a card's number and color must not have been played earlier (if a card of the same number and color was already played in a previous round as a valid move, it cannot be repeated). Moreover, each play must follow an additional rule regarding the "round wind".

For every round, the first card played determines the round wind (its color is called the round wind). In that round every player is expected to play a card with the same color as the round wind if possible. In other words, if a player is able to play a card that results in the same color as the round wind then he must do so. If a player, on his turn, plays a valid card whose color is different from the round wind, then from that moment on he is permanently banned from playing a card that matches the round wind in any future round. (Note that a paradox move—see below—does not count as a played card.)

The order of play in each round is determined as follows. In the first round, the first player is Sonja and the players then take turns in clockwise order. In subsequent rounds, the first player is the winner of the previous round, and the order continues clockwise from that player.

The outcome of each round is determined by the following rules (only valid moves are considered):

  • If there is at least one red card played, the winner is the player who played the red card with the largest number.
  • If no red card was played, the winner is the player among those who played a card matching the round wind (i.e. the color of the first played card) with the largest number.

Sometimes a move may violate a rule. A play is considered a paradox if:

  • The combination of number and color has been played before (in a valid play), or
  • The player has been banned from playing a card with the current round wind color and nevertheless attempts to play a card with that color.

Paradox moves are ignored – they do not count towards determining the winner of the round, and if it is the first time that the card is attempted, it is not considered as having been played (so the card remains in the player’s hand for a future round). It is guaranteed that the first move of every round is never a paradox move.

Given the sequence of cards played in n rounds (each round consists of 5 plays in order), your task is to determine how many paradox moves occurred, and for each paradox move output the round number (1-indexed) and the name of the player who made the paradox move. If multiple paradox moves occur in a round, output each in the order they occurred.

Input Format: The input starts with an integer n denoting the number of rounds. This is followed by 5×n lines. In each round, the players play in order. For the first round the order is: Sonja, Viktor, Igor, Lea, Marino (this is derived from the clockwise order starting at Sonja, given the seating arrangement Igor, Lea, Marino, Sonja, Viktor). In subsequent rounds, the order starts from the winner of the previous round and proceeds in clockwise order. Each play is represented by an integer (the card number) and a string (the chosen color) separated by a space.

Output Format: The first line of the output should contain a single integer indicating the total number of paradox moves that occurred in the entire game. For each paradox move, output a line containing two items: the round number (1-indexed) and the name of the player who played a paradox move, separated by a space. The order of these lines should follow the order in which the paradox moves occurred.

inputFormat

The input begins with a single integer n (the number of rounds). Following that are 5×n lines; each line contains an integer and a string (separated by a space) representing the number on the card and its color, respectively. The plays are given in the order in which they occur. For the first round, the order of play is: Sonja, Viktor, Igor, Lea, Marino. For subsequent rounds, the order starts with the winner of the previous round and continues clockwise (the seating order is: Igor, Lea, Marino, Sonja, Viktor).

outputFormat

Output the total number of paradox moves in the game on the first line. Then, for each paradox move, output a line with two items: the round number (1-indexed) and the name of the player who made the paradox move, separated by a space. If there are no paradox moves, output just 0.

sample

2
1 red
2 red
1 blue
3 red
1 red
4 red
1 red
2 blue
3 red
2 red
4

1 Marino 2 Marino 2 Viktor 2 Igor

</p>