atcoder#ARC109C. [ARC109C] Large RPS Tournament
[ARC109C] Large RPS Tournament
Score : points
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
.
- 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
.
3 2
RPS
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
11 1
RPSSPRSPPRS
P
1 100
S
S