Invisible Rally
View as PDFYou are watching Ian and Yakov's legendary table tennis match. Unfortunately, your view is blocked by a pillar.
Luckily, your friend can see the table clearly and is also very loud. Use your friend's exclamations to determine the final score of each game.
The players stand at opposite ends of a table, with a net separating their sides. During a point, the ball is on exactly one player's side, and only that player may attempt to hit it.
The match follows these rules:
- The match consists of one or more consecutive games. Both players start each game with zero points.
- Each point begins with a serve: the ball starts on the server's side, and the server attempts the first hit. The point ends when either player is awarded one point.
- A game ends as soon as a player has at least
points and leads by at least
points.
- Ian serves first in the first game. The players alternate who serves first in each game.
- Within each game, the players take turns serving for two points each. For example, if Ian
serves first, he is the server for points
and
, Yakov is the server for points
and
, and so on. These point numbers count only awarded points, not lets. Once both players have at least
points, the server changes after every point instead.
Every time a player attempts to hit the ball, including a serve or a miss, your friend makes exactly one of the following exclamations. The hitter is the player attempting the hit, and the receiver is the other player.
ooh: The hitter sends the ball cleanly over the net. The point continues with the ball now on the receiver's side.ahh: The hitter misses the ball. The receiver wins the point.boo: The ball touches the net as the hitter sends it over. If this is a serve, it is a let: no point is awarded, and the same player serves again. A let does not count towards a change of server. Otherwise, the receiver fails to return the ball and the hitter wins the point.SMASH!: The hitter attempts a smash. If the hitter's score in the current game is at least the receiver's score, the smash succeeds and the hitter wins the point. Otherwise, the receiver wins the point. A serve may also be a smash.
An exclamation that awards a point describes the entire end of that point; there is no extra
exclamation for the receiver's failure after boo or for the outcome of SMASH!.
Input
The first line contains an integer (
), the number of
exclamations.
Each of the next lines contains one exclamation
, one of
ooh, ahh,
boo, or SMASH!, in chronological order.
It is guaranteed that the exclamations describe a valid match starting from the first serve. If a game ends and exclamations remain, the next exclamation starts the next game. The last exclamation ends a game.
Output
On the first line, print a single integer , the number of games played.
On the -th of the next
lines, print two space-separated integers: Ian's final score
and Yakov's final score in game
, in that order.
Example 1
Input
15
boo
SMASH!
ahh
ooh
boo
ahh
ahh
SMASH!
SMASH!
SMASH!
SMASH!
SMASH!
SMASH!
SMASH!
SMASH!
Output
1
11 2
Explanation
The opening boo is a let, so Ian serves again and wins the first point with a smash.
Yakov wins the next point when Ian misses his serve. On the third point, Yakov serves
with ooh and Ian replies with boo; since this is not a serve, Ian wins the point.
After two more missed serves, Ian leads to
. Every remaining smash awards Ian
a point: his smashes succeed while Yakov's fail. Ian wins the game
to
.
Comments