CF1380B.Universal Solution

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string s=s1s2sns = s_1 s_2 \dots s_{n} of length nn where each letter is either R, S or P.

While initializing, the bot is choosing a starting index pospos ( 1posn1 \le pos \le n ), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of sposs_{pos} :

  • if sposs_{pos} is equal to R the bot chooses "Rock";
  • if sposs_{pos} is equal to S the bot chooses "Scissors";
  • if sposs_{pos} is equal to P the bot chooses "Paper";

In the second round, the bot's choice is based on the value of spos+1s_{pos + 1} . In the third round — on spos+2s_{pos + 2} and so on. After sns_n the bot returns to s1s_1 and continues his game.

You plan to play nn rounds and you've already figured out the string ss but still don't know what is the starting index pospos . But since the bot's tactic is so boring, you've decided to find nn choices to each round to maximize the average number of wins.

In other words, let's suggest your choices are c1c2cnc_1 c_2 \dots c_n and if the bot starts from index pospos then you'll win in win(pos)win(pos) rounds. Find c1c2cnc_1 c_2 \dots c_n such that win(1)+win(2)++win(n)n\frac{win(1) + win(2) + \dots + win(n)}{n} is maximum possible.

输入格式

The first line contains a single integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases.

Next tt lines contain test cases — one per line. The first and only line of each test case contains string s=s1s2sns = s_1 s_2 \dots s_{n} ( 1n21051 \le n \le 2 \cdot 10^5 ; si{R,S,P}s_i \in \{\text{R}, \text{S}, \text{P}\} ) — the string of the bot.

It's guaranteed that the total length of all strings in one test doesn't exceed 21052 \cdot 10^5 .

输出格式

For each test case, print nn choices c1c2cnc_1 c_2 \dots c_n to maximize the average number of wins. Print them in the same manner as the string ss .

If there are multiple optimal answers, print any of them.

输入输出样例

  • 输入#1

    3
    RRRR
    RSP
    S

    输出#1

    PPPP
    RSP
    R

说明/提示

In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all n=4n = 4 rounds, so the average is also equal to 44 .

In the second test case:

  • if bot will start from pos=1pos = 1 , then (s1,c1)(s_1, c_1) is draw, (s2,c2)(s_2, c_2) is draw and (s3,c3)(s_3, c_3) is draw, so win(1)=0win(1) = 0 ;
  • if bot will start from pos=2pos = 2 , then (s2,c1)(s_2, c_1) is win, (s3,c2)(s_3, c_2) is win and (s1,c3)(s_1, c_3) is win, so win(2)=3win(2) = 3 ;
  • if bot will start from pos=3pos = 3 , then (s3,c1)(s_3, c_1) is lose, (s1,c2)(s_1, c_2) is lose and (s2,c3)(s_2, c_3) is lose, so win(3)=0win(3) = 0 ;

The average is equal to 0+3+03=1\frac{0 + 3 + 0}{3} = 1 and it can be proven that it's the maximum possible average. A picture from Wikipedia explaining "Rock paper scissors" game:

首页