Crazy Time
InterviewTime limit1sMemory limit1024 MB
Given the order of flipped cards, output the time each turn must be called and whether players slap, under the reverse and sync rules.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Somewhere in the universe, there are beings who keep time flowing by counting it. After living through eons, they invented a counting game to make timekeeping more fun. It is called "Crazy Time"!
Before starting Crazy Time, shuffle the time cards well and deal them so that each player gets as close to the same number of cards as possible. Time cards have a front and a back. The front shows a clock picture and a time. There are three kinds of clock pictures: wall clock, wristwatch, and hourglass. Each player stacks the cards they receive face down in front of them to form a personal pile.
The game proceeds as follows.
- On their turn, a player flips the top card of their personal pile and calls out the time for this turn. The first player starts with "1 o'clock".
- Turns go clockwise. Unless another rule interferes, each player adds hour to the time just called. If the previous time was "12 o'clock", the next player calls "1 o'clock".
However, the flipped card may require a different way of calling out or a different action. Two kinds of time rules apply by default.
- Reverse time rule: When someone flips an hourglass card, time starts flowing backward. Players must call out "2 o'clock", "1 o'clock", "12 o'clock" in that order. Each time an hourglass card is flipped, the direction of time reverses.
- Sync rule: If the time a player calls out matches the time printed on the flipped card, all players must immediately slap the center of the game board with their palms.

Figure C.1: Reverse time rule. Flipping an hourglass card makes time flow backward.

Figure C.2: Sync rule. When the called time matches the time on the flipped card, players slap the center of the board.
There is also one principle that must always be followed.
- Overload principle: If a flipped card triggers two or more rules at the same time, none of those rules applies. For example, if the reverse time rule and the sync rule are triggered together, neither applies.
A player who calls out the wrong time, or who slaps the board last, takes a penalty token and places it next to their card pile. After a penalty token is given, the players return the flipped cards to the bottoms of their piles. The player who received the penalty then calls "1 o'clock" and the game resumes.
Hanbyeol wants to beat Eunha at Crazy Time and asked for your help. Using magic, Hanbyeol found out every card the next player is about to flip. Eunha is an excellent player and never calls out a wrong time, so no penalty token is given through this method. When the sync rule applies, every player slaps at exactly the same moment, so it is hard to tell who slapped last. Because of that, they agreed to play without giving any penalty tokens, unlike a real game. Given the order of the flipped cards, output the time each player must call out and the action each player must take.
Input
The first line contains , the number of cards that will be flipped.
Each of the next lines contains one card. Each line has a string for the clock type and a positive integer for the time printed on the card, separated by a space.
is one of CLOCK, WATCH, or HOURGLASS. CLOCK is a wall clock, WATCH is a wristwatch, and HOURGLASS is an hourglass.
Output
Print lines. For each flipped card, print the time the player on that turn must call out and the action they must take, separated by a space.
The time is an integer from to . The action is YES if the player must slap the center of the board, and NO otherwise.
Constraints
- All numbers in the input are integers.