305731: CF1082B. Vova and Trophies

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Vova and Trophies

题意翻译

### 题目描述 你现在有 $n$ 枚奖牌,每枚奖牌为金牌或银牌。这些奖牌现在按顺序排成一排。现在你可以调换任意一对奖牌的位置,求金牌最长连续段。 ### 输入格式 第一行一个整数 $n$ $(2\le n\le 10^5)$ . 第二行一行字符串,表示你的奖牌。 ( $\texttt{G}$ 表示金牌,$\texttt{S}$ 表示银牌) ### 输出格式 输出一个整数表示答案。

题目描述

Vova has won $ n $ trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement as beautiful as possible — that means, to maximize the length of the longest such subsegment. Help Vova! Tell him the maximum possible beauty of the arrangement if he is allowed to do at most one swap.

输入输出格式

输入格式


The first line contains one integer $ n $ ( $ 2 \le n \le 10^5 $ ) — the number of trophies. The second line contains $ n $ characters, each of them is either G or S. If the $ i $ -th character is G, then the $ i $ -th trophy is a golden one, otherwise it's a silver trophy.

输出格式


Print the maximum possible length of a subsegment of golden trophies, if Vova is allowed to do at most one swap.

输入输出样例

输入样例 #1

10
GGGSGGGSGG

输出样例 #1

7

输入样例 #2

4
GGGG

输出样例 #2

4

输入样例 #3

3
SSS

输出样例 #3

0

说明

In the first example Vova has to swap trophies with indices $ 4 $ and $ 10 $ . Thus he will obtain the sequence "GGGGGGGSGS", the length of the longest subsegment of golden trophies is $ 7 $ . In the second example Vova can make no swaps at all. The length of the longest subsegment of golden trophies in the sequence is $ 4 $ . In the third example Vova cannot do anything to make the length of the longest subsegment of golden trophies in the sequence greater than $ 0 $ .

Input

题意翻译

### 题目描述 你现在有 $n$ 枚奖牌,每枚奖牌为金牌或银牌。这些奖牌现在按顺序排成一排。现在你可以调换任意一对奖牌的位置,求金牌最长连续段。 ### 输入格式 第一行一个整数 $n$ $(2\le n\le 10^5)$ . 第二行一行字符串,表示你的奖牌。 ( $\texttt{G}$ 表示金牌,$\texttt{S}$ 表示银牌) ### 输出格式 输出一个整数表示答案。

加入题单

上一题 下一题 算法标签: