P24796 [AtCoder] [ABC365D] AtCoder Janken 3
普及-
题目描述

Problem Description

Takahashi and Aoki played rock-paper-scissors (RPS) for \( N \) rounds.

Aoki's hands are represented by a string \( S \) of length \( N \) consisting of R, P, and S. The hand Aoki played in the \( i \)-th round (\( 1 \leq i \leq N \)) is rock if the \( i \)-th character of \( S \) is R, paper if it is P, and scissors if it is S.

For Takahashi's hands, it is known that they satisfy the following conditions:

  • Takahashi never lost to Aoki.
  • For \( i = 1, 2, \ldots, N-1 \), the hand Takahashi played in the \( i \)-th round is different from the hand he played in the \( i+1 \)-th round.

Find the maximum possible number of rounds Takahashi could have won.

It can be proven that there exists a sequence of Takahashi's hands that satisfies the conditions.

Input Format

The input is given from the standard input in the following format:

\( N \) \( S \)

Output Format

Output the answer.

Sample Input and Output

Sample Input #1

6
PRSSRS

Sample Output #1

5

Sample Input #2

10
SSSSSSSSSS

Sample Output #2

5

Sample Input #3

24
SPRPSRRRRRPPRPRPSSRSPRSS

Sample Output #3

18

Notes/Hints

Constraints

  • \( 1 \leq N \leq 2 \times 10^5 \)
  • \( S \) is a string of length \( N \) consisting of R, P, and S.
  • \( N \) is an integer.

Sample Explanation 1

Aoki played paper, rock, scissors, scissors, rock, and scissors in the 6 rounds, respectively. Takahashi can win in rounds 1, 2, 3, 5, and 6 by playing scissors, paper, rock, paper, and rock, respectively. There is no sequence of Takahashi's hands that allows him to win all 6 rounds while satisfying the conditions, so output 5.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
6 PRSSRS
样例输出
5