QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 128 MB Puntuación total: 100 Hackeable ✓

#16095. The Big Bang Theory Version of Rock-Paper-Scissors

Estadísticas

Rock-paper-scissors is a common game: rock beats scissors, scissors beats paper, and paper beats rock. If both players choose the same gesture, it is a draw. In the 8th episode of the second season of The Big Bang Theory, an upgraded version of rock-paper-scissors was introduced. This version adds two new gestures to the traditional game:

  • Spock: One of the protagonists of Star Trek.
  • Lizard: An antagonist from Star Trek.

The win-loss relationships for these five gestures are shown in Table 1, which lists the results for Player A vs. Player B.

A\B Scissors Rock Paper Lizard Spock
ScissorsDrawLossWinWinLoss
RockDrawLossWinLoss
PaperDrawLossWin
LizardDrawWin
SpockDraw

Table 1 Win-loss relationships for the upgraded rock-paper-scissors

Now, Player A and Player B are playing this upgraded version. It is known that their gestures follow a periodic pattern, though the cycle lengths are not necessarily equal. For example: if Player A plays with a cycle of length $6$ ("Rock-Paper-Rock-Scissors-Lizard-Spock"), their sequence of gestures is "Rock-Paper-Rock-Scissors-Lizard-Spock-Rock-Paper-Rock-Scissors-Lizard-Spock-...". If Player B plays with a cycle of length $5$ ("Scissors-Rock-Paper-Spock-Lizard"), their sequence of gestures is "Scissors-Rock-Paper-Spock-Lizard-Scissors-Rock-Paper-Spock-Lizard-...".

Given that Player A and Player B play $N$ rounds in total, the winner of each round gets $1$ point, and the loser gets $0$ points. In the event of a draw, both players get $0$ points. Please calculate the final scores of both players after $N$ rounds.

Input

The first line contains three integers: $N, N_A, N_B$, representing the total number of rounds, the cycle length of Player A, and the cycle length of Player B, respectively. The numbers are separated by a space.

The second line contains $N_A$ integers representing the pattern of Player A, and the third line contains $N_B$ integers representing the pattern of Player B. Here, 0 represents "Scissors", 1 represents "Rock", 2 represents "Paper", 3 represents "Lizard", and 4 represents "Spock". The numbers are separated by a space.

Output

Output a single line containing two integers separated by a space, representing the scores of Player A and Player B, respectively.

Examples

Input 1

10 5 6
0 1 2 3 4
0 3 4 2 1 0

Output 1

6 2

Input 2

9 5 5
0 1 2 3 4
1 0 3 2 4

Output 2

4 4

Constraints

For $100\%$ of the data, $0 < N \leq 200, 0 < N_A \leq 200, 0 < N_B \leq 200$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.