#ARC109C. [ARC109C] Large RPS Tournament

[ARC109C] Large RPS Tournament

Score : 500500 points

Problem Statement

To decide which is the strongest among Rock, Paper, and Scissors, we will hold an RPS tournament. There are 2k2^k players in this tournament, numbered 00 through 2k12^k-1. Each player has his/her favorite hand, which he/she will use in every match.

A string ss of length nn consisting of R, P, and S represents the players' favorite hands. Specifically, the favorite hand of Player ii is represented by the ((i mod n)+1)((i\text{ mod } n) + 1)-th character of ss; R, P, and S stand for Rock, Paper, and Scissors, respectively.

For ll and rr such that rlr-l is a power of 22, the winner of the tournament held among Players ll through r1r-1 will be determined as follows:

  • If rl=1r-l=1 (that is, there is just one player), the winner is Player ll.
  • If rl2r-l\geq 2, let m=(l+r)/2m=(l+r)/2, and we hold two tournaments, one among Players ll through m1m-1 and the other among Players mm through r1r-1. Let aa and bb be the respective winners of these tournaments. aa and bb then play a match of rock paper scissors, and the winner of this match - or aa if the match is drawn - is the winner of the tournament held among Players ll through r1r-1.

Find the favorite hand of the winner of the tournament held among Players 00 through 2k12^k-1.

Notes

  • a mod ba\text{ mod } b denotes the remainder when aa is divided by bb.
  • 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 beats S;
    • P beats R;
    • S beats P.
  • If both players choose the same hand, the match is drawn;
  • R beats S;
  • P beats R;
  • S beats P.

Constraints

  • 1n,k1001 \leq n,k \leq 100
  • ss is a string of length nn consisting of R, P, and S.

Input

Input is given from Standard Input in the following format:

nn kk

ss

Output

Print the favorite hand of the winner of the tournament held among Players 00 through 2k12^k-1, as R, P, or S.

3 2
RPS
P
  • The favorite hand of the winner of the tournament held among Players 00 through 11 is P.
  • The favorite hand of the winner of the tournament held among Players 22 through 33 is R.
  • The favorite hand of the winner of the tournament held among Players 00 through 33 is P.

Thus, the answer is P.

P
 ┌─┴─┐
 P   R
┌┴┐ ┌┴┐
R P S R
11 1
RPSSPRSPPRS
P
1 100
S
S