paradoks — COCI CONTEST_#2
Task type: batch | Time limit: 1 s | Memory limit: 512 MB | Difficulty: 9
Algorithms: ad-hoc, simulation, circular traversal, state management

# Task Paradoks
### Croatian Open Competition in Informatics
### Round 2, November 9th 2024

One full moon evening, when the clock struck midnight, five friends found themselves ready to play a game as mysterious as that night.

They sat in a **circle**, in clockwise order: Igor, Lea, Marino, Sonja, and Viktor. The game consists of *N* rounds. The first round is started by Sonja, and each subsequent round is started by the winner of the previous round.

![](_page_0_Picture_5.jpeg)

Each player holds *N* cards in their hand. All cards are colorless and have a natural number between 1 and 9 on them. When a player plays a card, they choose the color for that card. They may choose one of four colors (red, blue, yellow, green) provided that such a card (combination of that number and color) has not already been played in the game. In the rest of the text, the term "playing a blue card," for example, refers to the procedure of playing the card and declaring it to be blue.

In each round, the players, in clockwise order, play one card each until the turn reaches the player who started the round, i.e., until each player has played one card. The first card played in a round determines the so-called *round color*, and all subsequent players are required to play cards of that color. If any player fails to play a card of the current round color, it is assumed that the player has no such color card in their hand – and they are prohibited from playing that color card **for the rest of the game.**

The winner of each round is:

*   The person who played the red card with the highest number.
*   If no red cards were played, the person who played the highest number of the round color.

Sometimes, players make a move that they should not have: either they play a card that has already been played or play a card of a color they previously declared they no longer have. This play is called a *paradox* (in Croatian: "paradoks"). When a paradox occurs, the play is completely ignored in calculating the round's winner and the rest of the game. For example, if a card is played for the first time as a paradox, for the rest of the game, it is treated as though it has not yet been played. It is guaranteed that the first player in a round will never play a paradox in that round.

Our heroes haven't seen each other for a long time and haven't been paying close attention to the game, so they ask for your help. Write a program that, for the sequentially listed played cards by round, prints how many paradoxes occurred and lists them in the order they happened. For each paradox, print the round in which it occurred and the player who caused it.

## Input

The first line of input contains a natural number *N* (1 ≤ *N* ≤ 10), the number of rounds.

In the next *N* lines of input, there are 5 words, each 2 characters long, representing the cards played in that round, in the order they were played. (Caution: the first player in each round is not necessarily the same.)

The first character of each word represents the color of the card the player played and will be one of the following letters: 'C' –red, 'P' – blue, 'Y' – yellow, 'Z' – green. The second character of each word will be a natural number between 1 and 9 (inclusive), representing the number on the card.

For example, the word 'Y5' would represent a yellow card with the number 5.

## Output

Print a single number *a*, the number of paradoxes that occurred.

In next *a* lines, for each of the *a* paradoxes, print the round number and the name of the player who

![](_page_1_Picture_0.jpeg)

caused it, in uppercase letters.

Paradoxes should be printed in the order they occurred.

### Scoring

| Subtask | Points | Constraints                                                                                                |
| :------ | :----- | :--------------------------------------------------------------------------------------------------------- |
| 1       | 10     | Sonja will be the winner of all rounds, and all paradoxes will occur due to repeating a card that has already been played. |
| 2       | 10     | All paradoxes that occur will be caused by repeating a card that has already been played.                  |
| 3       | 30     | No additional constraints.                                                                                 |

### Examples

| input                         | input                         | input         |
| :---------------------------- | :---------------------------- | :------------ |
| 4                             | 3                             | 1             |
| Y5 Z3 Y6 C2 Y1               | P1 Y9 Z5 Y1 Z5               | Y4 P9 Y8 Z5 Z3 |
| Z4 Z7 Z2 Y2 P3               | P5 Y7 Z3 Y8 P1               |               |
| Z6 Z7 Z1 Y2 C2               | C6 Y8 P5 Z1 Z8               |               |
| P6 P8 P8 Z7 Y9               |                               |               |
| output                        | output                        | output        |
| 6                             | 4                             | 0             |
| 2 VIKTOR                      | 1 MARINO                      |               |
| 3 SONJA                       | 2 MARINO                      |               |
| 3 LEA                         | 3 VIKTOR                      |               |
| 4 VIKTOR                      | 3 IGOR                        |               |
| 4 IGOR                        |                               |               |
| 4 LEA                         |                               |               |

#### Clarification of the first example:

The course of the game is shown in the picture below (on the next page).

In round 1, Viktor and Lea did not play yellow cards (the color of the round), so it is assumed that they have no yellow cards left in their hands and are prohibited from declaring any card as yellow for the rest of the game. This is the reason for Viktor's paradox in round 2 and Lea's paradox in the last round.

**Notice:** that in round 2, due to the paradox, Viktor's move is ignored, and we don't draw any further conclusions. Also, the card Y2 is not considered played, which is why Igor does not get a paradox for playing that card in round 3.

All the paradoxes in rounds 3 and 4 (except the last one) happened because a card was played that had already been played earlier in the game.

![](_page_2_Picture_0.jpeg)

Starter code: