CF1082B.Vova and Trophies

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Vova has won nn 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 nn ( 2n1052 \le n \le 10^5 ) — the number of trophies.

The second line contains nn characters, each of them is either G or S. If the ii -th character is G, then the ii -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 44 and 1010 . Thus he will obtain the sequence "GGGGGGGSGS", the length of the longest subsegment of golden trophies is 77 .

In the second example Vova can make no swaps at all. The length of the longest subsegment of golden trophies in the sequence is 44 .

In the third example Vova cannot do anything to make the length of the longest subsegment of golden trophies in the sequence greater than 00 .

首页