Dart Scoring

No attempts yetTime limit1sMemory limit128 MB

Problem

Darts is played by throwing darts at a board. The board is divided into 20 sectors, numbered from 1 to 20. Each sector has a single, a double, and a triple scoring area, so a dart landing in sector 5 scores 5, 10, or 15 points depending on the area it hits. At the centre of the board are two concentric circles: the bull's eye, worth 50 points, and the outer bull, worth 25 points.

The game of 301 is played by two players who take turns throwing groups of three darts. Both players start with a score of 301, which counts down toward 0.

Starting to score. A player's throws do not count until that player first hits a double; the bull's eye counts as a double. Every dart thrown before that first double scores 0.

Deducting a turn. During a turn a player throws up to three darts. The value of each counting dart is subtracted, one dart at a time, from the score the player had at the start of the turn.

Finishing and going bust. To win, a player must bring their score to exactly 0 with a dart that is a double. A turn ends immediately, and no further darts are thrown, as soon as the running score drops below 2. When a turn ends:

  • if the running score is exactly 0 and the last dart was a double, that player wins and the game is over;
  • otherwise the player has gone bust: the turn is void and the score reverts to what it was at the start of the turn.

For example, suppose your score at the start of your turn is 10. You should aim for double 5 to finish. If instead you throw triple 3 (9), single 9, single 10, or anything worth more than 10, the running score becomes 1, a non-double 0, or a negative value — all below 2 — so your turn ends and your score stays at 10. Any smaller throw is subtracted temporarily and you keep throwing, still trying to finish on a double; if you succeed you win, and if the score instead drops below 2 the turn ends with your score back at 10.

A round consists of the first player taking a turn and then the second player taking a turn. Write a program that scores such games.

Input

The input describes a series of games. Each game is a sequence of throws that may span one or more lines. Every line except possibly the last line of a game contains exactly 10 throws; each throw is written as a specifier followed by a comma. A throw specifier is one of:

  • S, D, or T followed by a number from 1 to 20 — a single, double, or triple in that sector.
  • B for the bull's eye, or OB for the outer bull.
  • M if the dart missed (scores 0).
  • # to mark the end of a game.

The whole sequence of games is terminated by a line containing a single #.

Output

Print several lines for each game. The first line is the word Game, a space, and the game number (a running count starting at 1). After it, print one line per round, showing the two scores at the end of that round. Treat the game as starting with an empty round zero, so the first score line is always 301 301.

Each score is printed right-justified in a field of width 5, with the first player's score in the left column and the second player's in the right column. On the final line the winner's column shows the word Wins (right-justified in the width-5 field) and the loser's column shows the loser's score. Separate successive games with a single blank line.