This page is still under construction.

Parts of this page are still being built. What you see may change.

Rock Paper Scissors Lizard Spock

Time limit1sMemory limit256 MB

Summary
Leo recovers the computer's hidden move generator from n observed throws and prints the winning reply to each of the next m throws.
Level

Medium5 of 10

Topics
Brute force, Math, Simulation
Solved
No attempts yet

Problem

Leo plays rock, paper, scissors, lizard, Spock against his computer. The game runs in rounds, and in every round the two players pick one of five options at the same time: rock, paper, scissors, lizard, Spock. Each option beats exactly two of the other four.

optionbeats
rockscissors, lizard
paperrock, Spock
scissorspaper, lizard
lizardpaper, Spock
Spockrock, scissors

If both players pick the same option, the round is a draw.

Figure F.1: the mechanics of the game. Illustration by VidTheKid via Wikimedia Commons.

Leo's computer picks its option with a linear congruential generator. The generator uses a known prime p=127p = 127 and two fixed integers 0≤a<p0 \le a < p and 0≤b<p0 \le b < p that Leo does not know. It also keeps a state 0≤x<p0 \le x < p whose starting value Leo does not know either. Before every round the computer updates the state,

x←(a⋅x+b) mod p,x \leftarrow (a \cdot x + b) \bmod p,

and then reads its option out of this table.

x mod 5x \bmod 50011223344
optionrockpaperscissorslizardSpock

Leo watched the first nn rounds and wrote down everything the computer played. He wants to win every one of the next mm rounds. Two options beat any given option, and Leo always takes the one that comes first in the order rock, paper, scissors, lizard, Spock.

Print what Leo plays in each of the next mm rounds.

Input

The first line has two integers nn and mm (1≤n≤10001 \le n \le 1000, 1≤m≤10001 \le m \le 1000).

Each of the next nn lines holds one of the words rock, paper, scissors, lizard, Spock: what the computer played in that round, in order.

The recorded rounds come from a generator of the form above, and they determine the next mm options. Every triple (a,b,x)(a, b, x) that reproduces all nn recorded options produces the same mm options after them.

Output

Print mm lines. Line ii holds what Leo plays in round n+in + i: the option that beats the computer's choice in that round, and when two options beat it, the one that comes first in the order rock, paper, scissors, lizard, Spock.

Examples2

  1. Example 1

    Input
    12 6
    rock
    Spock
    Spock
    paper
    lizard
    paper
    scissors
    lizard
    rock
    scissors
    paper
    lizard
    
    Expected output
    paper
    paper
    paper
    paper
    rock
    paper
  2. Example 2

    Input
    12 6
    paper
    lizard
    paper
    Spock
    Spock
    rock
    lizard
    rock
    Spock
    paper
    paper
    rock
    
    Expected output
    paper
    rock
    paper
    paper
    rock
    scissors