#P1328. Rock-Paper-Scissors-Lizard-Spock

    ID: 14615 Type: Default 1000ms 256MiB

Rock-Paper-Scissors-Lizard-Spock

Rock-Paper-Scissors-Lizard-Spock

This problem is an extension of the classic Rock-Paper-Scissors game. In this version, two additional gestures are introduced: Lizard and Spock. The win rules are defined as follows in \(\LaTeX\):

[ \begin{array}{rcl} \text{Scissors} &\to& \text{Paper}\ \text{Paper} &\to& \text{Rock}\ \text{Rock} &\to& \text{Lizard}\ \text{Lizard} &\to& \text{Spock}\ \text{Spock} &\to& \text{Scissors}\ \text{Scissors} &\to& \text{Lizard}\ \text{Lizard} &\to& \text{Paper}\ \text{Paper} &\to& \text{Spock}\ \text{Spock} &\to& \text{Rock}\ \text{Rock} &\to& \text{Scissors} \end{array} ]

In each round, if one player's gesture defeats the opponent's gesture according to the rules above, that player scores 1 point; if it is a tie, neither scores a point.

Player A and Player B each follow a periodic sequence of gestures. For example, if Player A's periodic sequence is "rock paper rock scissors lizard spock" with period length 6, then his moves will repeat in that order. Similarly, Player B may have a different period length and sequence.

Your task is to simulate \(N\) rounds of the game and calculate the total scores for Player A and Player B.

inputFormat

The input consists of three parts:

  1. An integer \(N\) representing the total number of rounds.
  2. A line starting with an integer \(L_A\) (the length of Player A's gesture cycle) followed by \(L_A\) strings representing the gestures in order.
  3. A line starting with an integer \(L_B\) (the length of Player B's gesture cycle) followed by \(L_B\) strings representing the gestures in order.

The gestures are one of the following (all in lowercase): rock, paper, scissors, lizard, spock.

Example Input:

12
6 rock paper rock scissors lizard spock
5 scissors rock paper spock lizard

outputFormat

Output two integers separated by a space. The first integer is Player A's score, and the second integer is Player B's score after \(N\) rounds.

Example Output:

5 4

sample

12
6 rock paper rock scissors lizard spock
5 scissors rock paper spock lizard
5 4