Rock-Paper-Scissors
InterviewTime limit1sMemory limit1024 MB
Find the fewest rounds in which Pidol's moves leave between 1 and K friends, and print the moves that achieve it.
Problem
Pidol needs to give gifts to friends, but Pidol has prepared only gifts (). To divide the gifts as fairly as possible, Pidol picks at most 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 rounds. It starts with people, and in each round only the people who beat Pidol move on to the next round. As soon as at most people remain, the game ends and the gifts are handed out. If nobody remains, or if more than 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 (). Find how Pidol should play so that the gifts can be handed out using the fewest rounds.
Input
The first line contains , , and separated by spaces. (, ) The next lines each contain a string giving the moves of one friend. is the move in round , where S is scissors, R is rock, and P is paper. (, )
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 on the first line. () On the second line, print the string of Pidol's moves, where is the move in round , S is scissors, R is rock, and P is paper. (, ) 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.