One full moon evening, when the clock struck midnight, five friends found them-
selves 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.
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
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
The first line of input contains a natural number \(N\) (\(1 \le N \le 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.
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
caused it, in uppercase letters.
Paradoxes should be printed in the order they occurred.
| 서브태스크 | 점수 | 설명 |
|---|---|---|
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. |
4
Y5 Z3 Y6 C2 Y1
Z4 Z7 Z2 Y2 P3
Z6 Z7 Z1 Y2 C2
P6 P8 P8 Z7 Y96
2 VIKTOR
3 SONJA
3 LEA
4 VIKTOR
4 IGOR
4 LEA3
P1 Y9 Z5 Y1 Z5
P5 Y7 Z3 Y8 P1
C6 Y8 P5 Z1 Z84
1 MARINO
2 MARINO
3 VIKTOR
3 IGOR1
Y4 P9 Y8 Z5 Z30Clarification 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.