Golf Croquet

Simulate a golf croquet doubles game from a stroke record and report the score and standing once a team reaches 7 points.

Easy3SimulationImplementationStringNo attempts yetTime limit2sMemory limit512 MB

Problem

In golf croquet doubles, two teams of two players face each other. Every player owns one ball and hits it when their turn comes. A turn is one hit of the ball.

The court has 6 hoops. Each hoop is played twice in a prescribed order, once in each direction. The first team to knock one of its balls through the current hoop in the right direction takes that hoop and scores a point. The first team to reach 7 points wins. If the score reaches 6 to 6, one deciding hoop is played. No team ever goes past 7 points, because the game ends the moment the seventh hoop is won.

The balls are played in a fixed order: blue, red, black (blue's partner), yellow (red's partner). The first named team plays blue and black, the other team plays red and yellow.

Each stroke is recorded with one of four letters.

  • S: an ordinary stroke that does not make a hoop
  • H: a stroke that makes a hoop for the team that played it
  • D: a stroke that makes 2 hoops at once for the team that played it. The chance is tiny, but it does happen. A team already on 6 points takes only the first of the two hoops.
  • O: a stroke that sends an opponent's ball through the hoop and gives the opposing team a point. Almost nobody does this on purpose.

Input

The first line holds the name of the first team and the second line holds the name of the second team. A name is one or more words and is at most 30 characters long. The first named team plays blue and black.

The third line holds the number of recorded strokes SS. (0<S2550 < S \le 255) The game may already be over, or it may still be in progress.

The fourth line holds SS upper case letters with no spaces between them. Each letter is one of S, H, D, O. Blue plays the first stroke, then red, then black, then yellow, and the order repeats.

Output

Print one line. Start with the score in this form.

team1name x team2name y.

Here x is the first team's score and y is the second team's score. Print one space, then one of the following.

teamname has won.
teamname is winning.
All square.

If a team has reached 7 points, print that team's name followed by has won. If no team has 7 points and one team leads, print the leading team's name followed by is winning. If both scores are equal, print All square.

The game ends as soon as either team reaches 7 points, so ignore any strokes recorded after that.

Hint

In the first example Team Sally play blue and black, and The dragons play red and yellow. Blue makes hoop 1 with stroke 5, black makes hoop 2 with stroke 11, blue makes hoop 3 with stroke 17, and yellow makes hoop 4 with stroke 24, so the score is 3 to 1.