Invisible Rally

View as PDF

Submit solution

Points: 100
Time limit: 2.0s
PyPy 3 6.0s
Python 3 6.0s
Memory limit: 1G

Author:
Problem type

You 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:

  1. The match consists of one or more consecutive games. Both players start each game with zero points.
  2. 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.
  3. A game ends as soon as a player has at least 11 points and leads by at least 2 points.
  4. Ian serves first in the first game. The players alternate who serves first in each game.
  5. Within each game, the players take turns serving for two points each. For example, if Ian serves first, he is the server for points 1 and 2, Yakov is the server for points 3 and 4, and so on. These point numbers count only awarded points, not lets. Once both players have at least 10 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 N (1 \le N \le 2 \times 10^5), the number of exclamations.

Each of the next N lines contains one exclamation s_i, 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 M, the number of games played.

On the i-th of the next M lines, print two space-separated integers: Ian's final score and Yakov's final score in game i, 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 3 to 2. Every remaining smash awards Ian a point: his smashes succeed while Yakov's fail. Ian wins the game 11 to 2.


Comments

There are no comments at the moment.