#abc365d. D - AtCoder Janken 3

D - AtCoder Janken 3

Score : 400400 points

问题陈述

高桥和青木玩了 NN 次石头剪刀布。[注:在这个游戏里面,石头赢剪刀,剪刀赢布,布赢石头。]

青木的出招由一个长度为 NN 的字符串 SS 表示,由字符 RPS 组成。SS 的第 ii 个字符表示青木在第 ii 局游戏中的出招:R 表示石头,P 表示布,S 表示剪刀。

高桥的出招满足以下条件:

  • 高桥从未输给青木。
  • 对于 i=1,2,,N1i=1,2,\ldots,N-1,高桥在第 ii 局游戏中的出招与他在第 (i+1)(i+1) 局游戏中的出招不同。

确定高桥可能赢得的最大游戏数量。

保证存在一个满足这些条件的高桥的出招序列。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

Takahashi and Aoki played rock-paper-scissors NN times. [Note: In this game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock.]

Aoki's moves are represented by a string SS of length NN consisting of the characters R, P, and S. The ii-th character of SS indicates Aoki's move in the ii-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 i=1,2,,N1i=1,2,\ldots,N-1, Takahashi's move in the ii-th game is different from his move in the (i+1)(i+1)-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

  • 1N2×1051\leq N\leq2\times10 ^ 5
  • SS is a string of length NN consisting of R, P, and S.
  • NN is an integer.

Input

The input is given from Standard Input in the following format:

NN

SS

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 55.

Sample Input 2

10
SSSSSSSSSS

Sample Output 2

5

Sample Input 3

24
SPRPSRRRRRPPRPRPSSRSPRSS

Sample Output 3

18
}