Under construction

Still being built. Things may change

Rock-Paper-Scissors

Interview

Time limit1sMemory limit1024 MB

Summary
Find the fewest rounds in which Pidol's moves leave between 1 and K friends, and print the moves that achieve it.
Level

Medium5 of 10

Topics
Hash map, String
Solved
No attempts yet

Problem

Pidol needs to give gifts to NN friends, but Pidol has prepared only KK gifts (K<NK < N). To divide the gifts as fairly as possible, Pidol picks at most KK people by playing rock-paper-scissors, then gives one gift to each of them. If many people play at once, ties are very likely, so Pidol uses a rule where only the people who beat Pidol survive. The game runs for MM rounds. It starts with NN people, and in each round only the people who beat Pidol move on to the next round. As soon as at most KK people remain, the game ends and the gifts are handed out. If nobody remains, or if more than KK people are still left after the last round, the gifts cannot be handed out. Pidol does not want to play more than necessary, so Pidol wants to pick people as quickly as possible. Using mind reading, Pidol knows what each friend will play in round ii (1≤i≤M1 \le i \le M). Find how Pidol should play so that the gifts can be handed out using the fewest rounds.

Input

The first line contains NN, MM, and KK separated by spaces. (1≤K<N≤501 \le K < N \le 50, 1≤M≤501 \le M \le 50) The next NN lines each contain a string a1a2…aMa_1a_2\dots a_M giving the moves of one friend. aia_i is the move in round ii, where S is scissors, R is rock, and P is paper. (ai∈{R,S,P}a_i \in \{R,S,P\}, 1≤i≤M1 \le i \le M)

Output

If Pidol cannot hand out the gifts no matter how Pidol plays, print -1 on the first line. Otherwise, print the minimum number of rounds PP on the first line. (1≤P≤M1 \le P \le M) On the second line, print the string b1b2…bPb_1b_2\dots b_P of Pidol's moves, where bib_i is the move in round ii, S is scissors, R is rock, and P is paper. (bi∈{R,S,P}b_i \in \{R,S,P\}, 1≤i≤P1 \le i \le P) If there are several answers, print any one of them.

Hint

In the first sample, if Pidol plays paper in round 1, friends 3 and 4 remain. If Pidol then plays rock in round 2, only friend 3 remains, and the gifts can be handed out. In the second sample, no matter how Pidol plays, either all friends remain or all of them are eliminated, so the gifts cannot be handed out.

Examples2

  1. Example 1

    Input
    4 3 1
    RSP
    RSS
    SPS
    SRP
    
    Expected output
    2
    PR
    
  2. Example 2

    Input
    2 3 1
    PSR
    PSR
    
    Expected output
    -1