#abc365d. D - AtCoder Janken 3
D - AtCoder Janken 3
Score : points
问题陈述
高桥和青木玩了 次石头剪刀布。[注:在这个游戏里面,石头赢剪刀,剪刀赢布,布赢石头。]
青木的出招由一个长度为 的字符串 表示,由字符 R
、P
和 S
组成。 的第 个字符表示青木在第 局游戏中的出招:R
表示石头,P
表示布,S
表示剪刀。
高桥的出招满足以下条件:
- 高桥从未输给青木。
- 对于 ,高桥在第 局游戏中的出招与他在第 局游戏中的出招不同。
确定高桥可能赢得的最大游戏数量。
保证存在一个满足这些条件的高桥的出招序列。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
Takahashi and Aoki played rock-paper-scissors times. [Note: In this game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock.]
Aoki's moves are represented by a string of length consisting of the characters R
, P
, and S
. The -th character of indicates Aoki's move in the -th game: R
for Rock, P
for Paper, and S
for Scissors.
Takahashi's moves satisfy the following conditions:
- Takahashi never lost to Aoki.
- For , Takahashi's move in the -th game is different from his move in the -th game.
Determine the maximum number of games Takahashi could have won.
It is guaranteed that there exists a sequence of moves for Takahashi that satisfies these conditions.
Constraints
- is a string of length consisting of
R
,P
, andS
. - is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print the maximum number of games Takahashi could have won.
Sample Input 1
6
PRSSRS
Sample Output 1
5
In the six games of rock-paper-scissors, Aoki played Paper, Rock, Scissors, Scissors, Rock, and Scissors.
Takahashi can play Scissors, Paper, Rock, Scissors, Paper, and Rock to win the 1st, 2nd, 3rd, 5th, and 6th games.
There is no sequence of moves for Takahashi that satisfies the conditions and wins all six games, so print .
Sample Input 2
10
SSSSSSSSSS
Sample Output 2
5
Sample Input 3
24
SPRPSRRRRRPPRPRPSSRSPRSS
Sample Output 3
18