#arc109c. [arc109_c]Large RPS Tournament
[arc109_c]Large RPS Tournament
Problem Statement
To decide which is the strongest among Rock, Paper, and Scissors, we will hold an RPS tournament. There are players in this tournament, numbered through . Each player has his/her favorite hand, which he/she will use in every match.
A string of length consisting of R
, P
, and S
represents the players' favorite hands. Specifically, the favorite hand of Player is represented by the -th character of ; R
, P
, and S
stand for Rock, Paper, and Scissors, respectively.
For and such that is a power of , the winner of the tournament held among Players through will be determined as follows:
- If (that is, there is just one player), the winner is Player .
- If , let , and we hold two tournaments, one among Players through and the other among Players through . Let and be the respective winners of these tournaments. and then play a match of rock paper scissors, and the winner of this match - or if the match is drawn - is the winner of the tournament held among Players through .
Find the favorite hand of the winner of the tournament held among Players through .
Notes
- denotes the remainder when is divided by .
- The outcome of a match of rock paper scissors is determined as follows:
- If both players choose the same hand, the match is drawn;
R
beatsS
;P
beatsR
;S
beatsP
.
Constraints
- is a string of length consisting of
R
,P
, andS
.
Input
Input is given from Standard Input in the following format:
Output
Print the favorite hand of the winner of the tournament held among Players through , as R
, P
, or S
.
Sample Input 1
3 2
RPS
Sample Output 1
P
- The favorite hand of the winner of the tournament held among Players through is
P
. - The favorite hand of the winner of the tournament held among Players through is
R
. - The favorite hand of the winner of the tournament held among Players through is
P
.
Thus, the answer is P
.
P
┌─┴─┐
P R
┌┴┐ ┌┴┐
R P S R
Sample Input 2
11 1
RPSSPRSPPRS
Sample Output 2
P
Sample Input 3
1 100
S
Sample Output 3
S