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.


-----Input-----

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. 


-----Output-----

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


-----Examples-----
Input
10
GGGSGGGSGG

Output
7

Input
4
GGGG

Output
4

Input
3
SSS

Output
0



-----Note-----

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

Difficulty: MEDIUM_HARD

Solutions:
n = int(input())
s = input()
a = []
k = 1
for i in range(n - 1):
	if s[i] == 'G' and s[i + 1] == 'G':
		k += 1
	elif s[i] == 'G' and s[i + 1] == 'S':
		a.append([i, k])
		k = 1
if s[-1] == 'G':
	a.append([n - 1, k])
if len(a) == 0:
	print(0)
elif len(a) == 1:
	print(a[0][1])
elif len(a) == 2:
	ma = 0
	for i in a:
		ma = max(i[1], ma)
	ka = 0
	for i in range(len(a) - 1):
		if a[i + 1][0] - a[i + 1][1] + 1 - a[i][0] == 2:
			ka = max(a[i][1] + a[i + 1][1], ka)
	if ka > ma + 1:
		print(ka)
	else:
		print(ma + 1)
else:
	ma = 0
	for i in a:
		ma = max(i[1], ma)
	ka = 0
	for i in range(len(a) - 1):
		if a[i + 1][0] - a[i + 1][1] + 1 - a[i][0] == 2:
			ka = max(a[i][1] + a[i + 1][1], ka)
	print(max(ka, ma) + 1)


n = int(input())
row = input()
g = 0
s = 0
m = 0
leng = []
lens = []
for i in range(n):
	if row[i] == 'G':
		g += 1
	elif g != 0:
		if g > m:
			m = g
		leng.append(g)
		g = 0
if row[n - 1] == 'G':
	leng.append(g)
	if g > m:
		m = g
for i in range(n):
	if row[i] == 'S':
		s += 1
	elif s != 0:
		lens.append(s)
		s = 0
if row[n - 1] == 'S':
	lens.append(s)
if len(leng) == 0:
	print(0)
elif len(leng) == 1:
	print(leng[0])
else:
	if row[0] == 'S':
		lens = lens[1:len(lens)]
	m += 1
	ans = m
	for i in range(1, len(leng)):
		if lens[i - 1] == 1:
			if len(leng) == 2:
				if leng[0] + leng[1] > ans:
					ans = leng[0] + leng[1]
			elif leng[i] + leng[i - 1] + 1 > ans:
				ans = leng[i] + leng[i - 1] + 1
	print(ans)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import *
(n,) = I()
s = input()
c = s.count('G')
if c == 0:
	print(0)
	exit()
i = 0
while i < n and s[i] == 'S':
	i += 1
s = s[i:]
n = len(s)
l = []
i = 1
count = 1
while i < n:
	if s[i] == s[i - 1]:
		count += 1
	else:
		l.append(count)
		count = 1
	i += 1
l.append(count)
ans = l[0]
n = len(l)
if n > 2:
	for i in range(n):
		if i % 2 == 0:
			ans = max(ans, l[i] + 1)
l += [0]
for i in range(n):
	if i % 2 and l[i] == 1:
		if c - l[i - 1] - l[i + 1]:
			ans = max(ans, l[i - 1] + l[i + 1] + 1)
		else:
			ans = max(ans, l[i - 1] + l[i + 1])
print(ans)


import itertools as it
n = int(input())
A = [(trophy, len(list(gr))) for (trophy, gr) in it.groupby(input())]
if A[0][0] == 'S':
	A = A[1:]
if len(A) > 0 and A[-1][0] == 'S':
	A = A[:-1]
if len(A) == 0:
	print(0)
elif len(A) == 1:
	print(A[0][1])
elif len(A) == 3:
	if A[1][1] == 1:
		print(A[0][1] + A[2][1])
	else:
		print(max(A[0][1], A[2][1]) + 1)
else:
	best = max(map(lambda x: x[1], A[::2])) + 1
	for i in range(0, len(A) - 1, 2):
		if A[i + 1][1] == 1:
			best = max(best, A[i][1] + A[i + 2][1] + 1)
	print(best)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
N = int(input())
s = input()
A = [list(j) for (i, j) in groupby(s)]
if len(A) <= 2:
	print(s.count('G'))
else:
	ans = 0
	n = len(A)
	for i in range(n):
		if A[i][0] == 'G':
			l = len(A[i])
			ans = max(ans, l)
			if i + 2 < n or i - 2 >= 0:
				ans = max(ans, l + 1)
		elif len(A[i]) == 1:
			if i + 1 < n and i - 1 >= 0:
				ans = max(ans, len(A[i - 1]) + len(A[i + 1]))
			if (i + 3 < n or i - 3 >= 0) and (i + 1 < n and i - 1 >= 0):
				ans = max(ans, len(A[i - 1]) + len(A[i + 1]) + 1)
	print(ans)


n = int(input())
s = str(input())
last_seq = 0
curr_seq = 0
ans = 0
gcount = 0
i = 0
while i < n - 1:
	if s[i] == 'G':
		gcount += 1
		curr_seq += 1
		i += 1
	else:
		if curr_seq + last_seq > ans:
			ans = curr_seq + last_seq
		if s[i + 1] == 'G':
			last_seq = curr_seq
			curr_seq = 0
			i += 1
		else:
			if curr_seq > ans:
				ans = curr_seq
			curr_seq = 0
			last_seq = 0
			i += 2
if s[-1] == 'G':
	gcount += 1
	curr_seq += 1
if curr_seq + last_seq > ans:
	ans = curr_seq + last_seq
if gcount > ans:
	print(ans + 1)
else:
	print(ans)


n = int(input())
s = input()
res = 0
cur = 1
z = 0
for i in s:
	if i == 'G':
		cur += 1
		z += 1
		res = max(res, cur)
	else:
		cur = z + 1
		z = 0
print(min(res, s.count('G')))


N = int(input())
S = input()
G = S.count('G')
if G == 0:
	print(0)
elif G == N:
	print(N)
else:
	num = 0
	tmp = 0
	pre = 0
	for i in range(N):
		if S[i] == 'G':
			tmp += 1
		else:
			if tmp + pre < G:
				num = max(tmp + pre + 1, num)
			else:
				num = max(tmp + pre, num)
			pre = tmp
			tmp = 0
	if tmp + pre < G:
		num = max(tmp + pre + 1, num)
	else:
		num = max(tmp + pre, num)
	print(num)


__author__ = 'tanunia'
from sys import stdin
n = int(stdin.readline())
t = stdin.readline().strip()
lst = []
cur_gold_len = 0
cur_silver_len = 0
gold_packs = 0
for c in t:
	if c == 'G':
		if cur_gold_len == 0:
			if cur_silver_len > 0:
				lst.append(['S', cur_silver_len])
				cur_silver_len = 0
		cur_gold_len += 1
	else:
		if cur_silver_len == 0:
			if cur_gold_len > 0:
				lst.append(['G', cur_gold_len])
				gold_packs += 1
				cur_gold_len = 0
		cur_silver_len += 1
if cur_gold_len > 0:
	lst.append(['G', cur_gold_len])
	gold_packs += 1
else:
	lst.append(['S', cur_silver_len])
max_seq = 0
for i in range(len(lst)):
	if lst[i][0] == 'G':
		if gold_packs > 1:
			max_seq = max(max_seq, lst[i][1] + 1)
		else:
			max_seq = max(max_seq, lst[i][1])
		if i > 1:
			if lst[i - 1][0] == 'S' and lst[i - 1][1] == 1:
				if gold_packs > 2:
					max_seq = max(max_seq, lst[i - 2][1] + lst[i][1] + 1)
				else:
					max_seq = max(max_seq, lst[i - 2][1] + lst[i][1])
print(max_seq)


n = int(input())
arr = list(map(str, input()))
cnt = []
(g, s) = (0, 0)
seg = 0
ind = []
idx = 0
for i in range(n):
	if arr[i] == 'S':
		if g != 0:
			ind.append(idx)
			cnt.append(g)
			idx += 1
			seg += 1
			g = 0
		s += 1
	else:
		if s != 0:
			cnt.append(-s)
			idx += 1
			s = 0
		g += 1
if g != 0:
	cnt.append(g)
	ind.append(idx)
	idx += 1
	seg += 1
if s != 0:
	cnt.append(-s)
	idx += 1
if seg == 0:
	print(0)
elif seg == 1:
	for i in cnt:
		if i > 0:
			print(i)
			break
elif seg == 2:
	(id1, id2) = (ind[0], ind[1])
	if cnt[id1 + 1] == -1:
		print(cnt[id1] + cnt[id2])
	else:
		print(max(cnt[id1], cnt[id2]) + 1)
else:
	ans = -1
	for i in range(1, len(ind)):
		(id1, id2) = (ind[i - 1], ind[i])
		if cnt[id1 + 1] == -1:
			ans = max(ans, cnt[id1] + cnt[id2] + 1)
		else:
			ans = max(ans, cnt[id1] + 1, cnt[id2] + 1)
	print(ans)


n = int(input())
src = []
s = input() + '#'
tot = s.count('G')
t = s[0]
l = 0
mx = 0
for i in range(n + 1):
	if t == s[i]:
		l += 1
	else:
		if t == 'G':
			mx = max(l, mx)
		src.append([t, l])
		l = 1
		t = s[i]
if mx != tot:
	mx += 1
for i in range(2, len(src)):
	if src[i][0] == 'S':
		continue
	if src[i - 1][1] != 1:
		continue
	b = 0
	if tot != src[i - 2][1] + src[i][1]:
		b = 1
	mx = max(mx, src[i - 2][1] + src[i][1] + b)
print(mx)


n = int(input())
s = input()
ans = 0
(sc, gc, pi, ci) = (0, 0, -1, -1)
for i in range(1, n + 1):
	if s[i - 1] == 'G':
		gc += 1
	else:
		sc += 1
		if pi == -1:
			ans = max(ans, i - 1)
		else:
			ans = max(ans, i - 1 - pi)
		pi = ci
		ci = i
if sc == 1:
	print(n - 1)
	exit()
if sc == 2 and (s[0] == 'S' or s[n - 1] == 'S'):
	print(n - 2)
	exit()
if pi == -1:
	ans = max(ans, n)
else:
	ans = max(ans, n - pi)
print(min(ans, gc))


import sys
from math import ceil, sqrt
input = sys.stdin.readline
n = int(input())
s = input().strip()
last = 'S'
ans = []
count = 0
freq = {'S': 0, 'G': 0}
for i in range(n):
	freq[s[i]] += 1
	if s[i] != last:
		ans.append((count, last))
		last = s[i]
		count = 1
	else:
		count += 1
ans.append((count, last))
ans.pop(0)
if freq['G'] == 0:
	print(0)
	return
final = max([x[0] for x in ans if x[1] == 'G'])
if freq['G'] > final:
	final += 1
for i in range(len(ans) - 2):
	if ans[i][1] == 'G' and ans[i + 1][1] == 'S' and (ans[i + 1][0] == 1) and (ans[i + 2][1] == 'G'):
		if freq['G'] > ans[i][0] + ans[i + 2][0]:
			final = max(final, ans[i][0] + ans[i + 2][0] + 1)
		else:
			final = max(final, ans[i][0] + ans[i + 2][0])
print(final)


n = int(input())
L = [x for x in input()]
S = []
beggining = L[0]
temp = 1
for i in range(1, n):
	if L[i] == L[i - 1]:
		temp += 1
	else:
		S.append((temp, L[i - 1]))
		temp = 1
S.append((temp, L[n - 1]))
high = 0
goldCount = 0
for i in S:
	if i[1] == 'G':
		goldCount += 1
		if i[0] > high:
			high = i[0]
start = high
goldCheck = goldCount >= 3
if len(S) == 1:
	if L[0] == 'G':
		print(S[0][0])
	elif L[0] == 'S':
		print(0)
else:
	for i in range(1, len(S) - 1):
		if S[i][0] == 1 and S[i][1] == 'S':
			if S[i - 1][0] + S[i + 1][0] + goldCheck > high:
				high = S[i - 1][0] + S[i + 1][0] + goldCheck
	print(max(high, start + (goldCount >= 2)))


n = int(input())
ks = input().strip()
prev_g_seq_len = 0
cur__g_seq_len = 0
prev_is_s = True
res = 0
for j in ks:
	if j == 'S':
		prev_g_seq_len = cur__g_seq_len
		cur__g_seq_len = 0
	else:
		cur__g_seq_len += 1
	res = max(res, prev_g_seq_len + cur__g_seq_len + 1)
mmm = ks.count('G')
res = min(mmm, res)
print(res)


def mi():
	return map(int, input().split())
n = int(input())
s = list(input())
for i in range(n):
	if s[i] == 'G':
		s[i] = 1
	else:
		s[i] = 0
a = []
i = 0
while i < n:
	if s[i] == 1:
		c = 0
		zc = 0
		pz = -1
		while i < n and zc <= 1:
			if s[i] == 1:
				c += 1
			else:
				zc += 1
				if zc == 1:
					pz = i
			i += 1
		a.append(c)
		if pz != -1:
			i = pz
	else:
		i += 1
if len(a) > 1:
	ans = max(a) + 1
	if ans > s.count(1):
		print(s.count(1))
	else:
		print(max(a) + 1)
elif len(a) == 1:
	print(a[0])
else:
	print(0)


n = int(input())
BAS = input()
s = BAS.split('S')
m = 0
if len(s) > 1:
	for elem in range(len(s) - 1):
		if len(s[elem]) > 0 or len(s[elem + 1]) > 0:
			if m < len(s[elem] + s[elem + 1]) + 1:
				m = len(s[elem] + s[elem + 1]) + 1
		elif m < len(s[elem] + s[elem + 1]):
			m = len(s[elem] + s[elem + 1])
	if m > BAS.count('G'):
		print(BAS.count('G'))
	else:
		print(m)
else:
	print(n)


def main():
	n = int(input())
	Gs = [len(i) for i in input().split('S')]
	total_G = sum(Gs)
	ln = len(Gs)
	if ln == 1:
		return Gs[0]
	else:
		beauty = [Gs[k] + Gs[k + 1] for k in range(ln - 1)]
		ma = max(beauty)
		if ma != total_G:
			return ma + 1
		else:
			return ma
print(main())


from itertools import groupby
n = int(input())
trophies = input().strip()
runs = [(i, len(list(s))) for (i, s) in groupby(trophies)]
if runs and runs[0][0] == 'S':
	runs.pop(0)
if runs and runs[-1][0] == 'S':
	runs.pop()
runs = [r[1] for r in runs]
if len(runs) == 0:
	print(0)
elif len(runs) == 1:
	print(runs[0])
elif len(runs) == 3:
	if runs[1] == 1:
		print(runs[0] + runs[2])
	else:
		print(max(runs[0], runs[2]) + 1)
else:
	longest = max((runs[i] for i in range(0, len(runs), 2))) + 1
	for i in range(1, len(runs), 2):
		if runs[i] == 1:
			longest = max(longest, runs[i - 1] + runs[i + 1] + 1)
	print(longest)


repeat = int(input())
tropy = input()
tropy += 'S'
front = 0
back = 0
mid = 0
maxmum = 0
silver = 0
maxg = 0
for i in tropy:
	if i == 'G':
		maxg += 1
for i in tropy:
	if i == 'G':
		front += 1
		silver = 0
		if front + back + mid <= maxg:
			maxmum = max(maxmum, front + back + mid)
	elif silver == 1:
		front = 0
		back = 0
		mid = 0
	else:
		if front + 1 <= maxg:
			maxmum = max(maxmum, front + 1)
		silver = 1
		back = front
		front = 0
		mid = 1
print(maxmum)


n = int(input())
s = input()
(x, y, m) = (0, 0, 0)
for i in s:
	if i == 'G':
		x = x + 1
	else:
		(x, y) = (0, x)
	m = max(m, x + y + 1)
print(min(m, s.count('G')))


import sys, os, io
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from sys import stdin
import math

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = 1
for _ in range(t):
	n = int(input())
	l = list(input())
	if l.count('G') == 0:
		print(0)
		continue
	if l.count('S') == 0:
		print(n)
		continue
	Maxlen = 1
	curlen = 1
	arr = []
	startG = -2
	if l[0] == 'G':
		startG = 0
	for i in range(1, n):
		if l[i] == l[i - 1]:
			if l[i] == 'G':
				curlen += 1
		elif l[i] == 'S':
			if startG != -2:
				arr.append([startG, i - 1])
		else:
			startG = i
	if l[-1] == 'G':
		arr.append([startG, n - 1])
	ans = 0
	ss = l.count('G')
	l = arr[:]
	for i in range(len(l) - 1):
		if l[i][1] + 2 == l[i + 1][0]:
			if ss > l[i][1] - l[i][0] + 1 + 1 + l[i + 1][1] - l[i + 1][0]:
				ans = max(l[i][1] - l[i][0] + 1 + 1 + l[i + 1][1] - l[i + 1][0] + 1, ans)
			else:
				ans = max(l[i][1] - l[i][0] + 1 + 1 + l[i + 1][1] - l[i + 1][0], ans)
	if len(l) == 1:
		ans = max(ans, l[0][1] - l[0][0] + 1)
	elif len(l) > 1:
		for i in range(len(l)):
			ans = max(ans, l[i][1] - l[i][0] + 1 + 1)
	print(ans)


n = int(input())
st = input()
i = 0
twos = False
goldblocks = 0
prev = 0
cur = 0
highest = 0
while i < n:
	if st[i] == 'G':
		cur = cur + 1
	elif st[i - 1] == 'G' and i > 0:
		if highest < cur + prev:
			highest = cur + prev
		prev = cur
		goldblocks += 1
		cur = 0
	else:
		prev = 0
		if goldblocks == 1:
			twos = True
	i = i + 1
else:
	if st[i - 1] == 'G':
		if highest < cur + prev:
			highest = cur + prev
		prev = cur
		goldblocks += 1
		cur = 0
if goldblocks <= 1:
	print(highest)
elif goldblocks == 2:
	if twos:
		print(highest + 1)
	else:
		print(highest)
else:
	print(highest + 1)


n = int(input())
s = '_' + input() + '_'
l = [0] * (n + 2)
con = 0
for i in range(n + 2):
	if s[i] == 'G':
		con += 1
	else:
		l[i] += con
		l[i - con - 1] += con
		con = 0
g = list(s).count('G')
print(min(g, max(l) + 1))


n = int(input())
s = input()
left_G = {}
cnt = 0
tot_G = 0
ans = 0
for i in range(len(s)):
	if s[i] == 'S':
		left_G[i] = cnt
		cnt = 0
	if s[i] == 'G':
		tot_G += 1
		cnt += 1
rt_g = 0
for i in range(len(s) - 1, -1, -1):
	if s[i] == 'S':
		if tot_G > left_G[i] + rt_g:
			ans = max(ans, left_G[i] + rt_g + 1)
		elif tot_G == left_G[i] + rt_g:
			ans = max(ans, left_G[i] + rt_g)
		rt_g = 0
	else:
		rt_g += 1
if rt_g != tot_G:
	print(ans)
else:
	print(rt_g)


import sys, os, io
n = int(input())
s = list(input())
a = [0]
for i in range(n):
	if s[i] == 'G':
		if a[-1] < 0:
			a.append(0)
		a[-1] += 1
	else:
		if a[-1] > 0:
			a.append(0)
		a[-1] -= 1
ans = max(a)
if len(a) == 1 or len(a) == 2 or (len(a) == 3 and a[0] < 0):
	print(max(ans, 0))
else:
	nm = 0
	for i in range(1, len(a) - 1):
		if a[i] == -1:
			nm = max(nm, a[i - 1] + a[i + 1])
	if len(a) == 3 or len(a) == 4 or (len(a) == 5 and a[0] < 0):
		print(max(ans + 1, nm))
	else:
		print(max(ans + 1, nm + 1))


n = int(input())
t = input().split('S')
u = list(filter(None, sorted(t, key=len)[::-1]))
if len(u) == 0:
	print(0)
elif 0 < len(u) < 2:
	print(len(u[0]))
else:
	temp = 0
	for i in range(len(t) - 1):
		temp = max(temp, len(t[i] + t[i + 1]) if len(u) == 2 else len(t[i] + t[i + 1] + 'G'))
	print(max(temp, len(u[0]) + 1))


numTrophies = int(input())
trophies = input()
goldSegments = trophies.split('S')
maxG = 0
if len(goldSegments) == 1:
	print(len(goldSegments[0]))
elif len(goldSegments) > numTrophies:
	print(0)
else:
	for i in range(len(goldSegments) - 1):
		segSum = len(goldSegments[i]) + len(goldSegments[i + 1]) + 1
		if segSum > maxG:
			maxG = segSum
	totG = 0
	for s in goldSegments:
		totG += len(s)
	if maxG > totG:
		maxG = totG
	print(maxG)


def main():
	count = int(input())
	arr = []
	bo = True
	start = -1
	string = input()
	for x in range(count):
		if string[x] == 'G':
			if bo:
				start = x
				bo = False
		elif string[x] == 'S':
			if not bo:
				bo = True
				arr.append((start, x))
	if not bo:
		arr.append((start, x + 1))
	if len(arr) == 0:
		print(0)
	elif len(arr) == 1:
		print(arr[0][1] - arr[0][0])
	elif len(arr) == 2:
		if arr[1][0] - 1 == arr[0][1]:
			print(arr[1][1] - arr[0][0] - 1)
		else:
			maxi = 0
			for x in arr:
				maxi = max(maxi, x[1] - x[0] + 1)
			print(maxi)
	else:
		maxi = 0
		for x in range(len(arr) - 1):
			if arr[x][1] + 1 == arr[x + 1][0]:
				maxi = max(maxi, arr[x + 1][1] - arr[x][0])
			maxi = max(maxi, arr[x][1] - arr[x][0] + 1)
		maxi = max(maxi, arr[-1][1] - arr[-1][0] + 1)
		print(maxi)
main()


import math
n = int(input())
data = list(input())
firstsilver = -1
secondsilver = -1
mdiff = [-1, -1, -1]
for i in range(0, n):
	if data[i] == 'S' and secondsilver == -1:
		secondsilver = i
	elif data[i] == 'S':
		firstsilver = secondsilver
		secondsilver = i
	diff = i - firstsilver
	if diff > mdiff[0]:
		mdiff = [diff, firstsilver, i, secondsilver]
if mdiff[1] == mdiff[3]:
	penalty = 0
else:
	penalty = 1
for i in range(0, n):
	if i not in list(range(mdiff[1] + 1, mdiff[2] + 1)):
		if data[i] == 'G':
			penalty = 0
print(mdiff[0] - penalty)


from itertools import groupby
n = int(input())
s = input()
cg = 0
gg = 0
lgg = 0

def fn(c, v):
	global cg, gg, lgg
	if c == 'G':
		cg += v
		gg += 1
		lgg = max(lgg, v)
	return (c, v)
groups = [fn(k, len(list(g))) for (k, g) in groupby(s)]
ans = lgg
if gg > 1:
	ans = lgg + 1
	for i in range(1, len(groups) - 1):
		(first, second, third) = groups[i - 1:i + 2]
		if first[0] == 'G' and third[0] == 'G' and (second[0] == 'S') and (second[1] == 1):
			if cg > first[1] + third[1]:
				ans = max(ans, first[1] + third[1] + 1)
			else:
				ans = max(ans, first[1] + third[1])
print(ans)


n = int(input())
s = input()
ls = []
last_index = -1
for i in range(n):
	if s[i] == 'G':
		last_index = i
		break
if last_index == -1:
	print(0)
	exit()
b = True
for i in range(last_index + 1, n):
	if s[i] == 'S' and b:
		ls.append((last_index, i - last_index))
		last_index = i + 1
		b = False
	elif s[i] == 'G' and (not b):
		last_index = i
		b = True
if s[-1] == 'G' and b and (last_index != n):
	ls.append((last_index, n - last_index))
if len(ls) <= 1:
	if len(ls) == 1:
		print(ls[0][1])
		exit()
	else:
		print(0)
		exit()
res = ls[0][1]
for i in range(1, len(ls)):
	if ls[i][0] - 1 == ls[i - 1][0] + ls[i - 1][1]:
		if len(ls) > 2:
			res = max(res, ls[i][1] + ls[i - 1][1] + 1)
		elif len(ls) == 2:
			res = max(res, ls[i - 1][1] + ls[i][1])
		else:
			res = max(res, ls[i][1])
	else:
		res = max(res, ls[i - 1][1] + 1, ls[i][1] + 1)
print(res)


from itertools import groupby

def solve(s):
	s = s.upper()
	groups = [(key, len(list(values))) for (key, values) in groupby(s)]
	if len(groups) == 1:
		if groups[0][0] == 'G':
			return groups[0][1]
		return 0
	if len(groups) == 2:
		if groups[0][0] == 'G':
			return groups[0][1]
		return groups[1][1]
	i = 2 if groups[0][0] == 'G' else 3
	pair = (-1, -1)
	max_gold = groups[i - 2][1]
	while i < len(groups):
		if groups[i][1] > max_gold:
			max_gold = groups[i][1]
		if groups[i - 1][1] == 1:
			assert groups[i - 1][0] == 'S'
			assert i - 2 >= 0
			new_pair = (groups[i - 2][1], groups[i][1])
			if sum(new_pair) > sum(pair):
				pair = new_pair
		i += 2
	if len(groups) < 5:
		if sum((key == 'G' for (key, _) in groups)) > 1:
			return max(sum(pair), max_gold + 1)
		return max(sum(pair), max_gold)
	if len(groups) == 5 and groups[0][0] == 'S':
		return max(sum(pair), max_gold + 1)
	return max(sum(pair), max_gold) + 1

def main():
	n = int(input())
	s = input()
	print(solve(s))
main()


one_before = 0
streak = 0
silver = 0
possible_longest = 0
gs = 0
a = input()
b = input()
for i in b:
	if i == 'G':
		streak += 1
		gs += 1
		silver = 0
	else:
		silver += 1
		possible_longest = max(streak + one_before, possible_longest)
		if silver == 1:
			one_before = streak
		else:
			one_before = 0
		streak = 0
possible_longest = max(streak + one_before, possible_longest)
if possible_longest < gs:
	print(possible_longest + 1)
else:
	print(possible_longest)


from itertools import groupby as gb
n = int(input())
s = input()
g = gb(s)
gl = []
for (k, v) in g:
	gl.append([k, len(list(v))])
l = len(gl)
if s[0] == 'S':
	if l == 1:
		print(0)
		return
	elif l <= 3:
		print(gl[1][1])
		return
if s[0] == 'G':
	if l <= 2:
		print(gl[0][1])
		return
res = 0
for (i, [k, v]) in enumerate(gl):
	if (k, v) == ('S', 1) and i not in (0, l - 1):
		if s[0] == 'S' and l <= 5:
			res = max(res, gl[i - 1][1] + gl[i + 1][1])
		elif s[0] == 'G' and l <= 4:
			res = max(res, gl[i - 1][1] + gl[i + 1][1])
		else:
			res = max(res, gl[i - 1][1] + gl[i + 1][1] + 1)
for (i, [k, v]) in enumerate(gl):
	if k == 'S' and v > 1:
		if i != 0:
			res = max(res, gl[i - 1][1] + 1)
		if i != l - 1:
			res = max(res, gl[i + 1][1] + 1)
print(res)


n = int(input())
s = input() + 'S'
s1 = s2 = sg = ans = 0
for c in s:
	if c == 'G':
		s1 += 1
	else:
		ans = max(ans, s1 + s2 + 1)
		s2 = s1
		s1 = 0
print(min(ans, sum((1 for c in s if c == 'G'))))


n = int(input())
s = input()
l = []
i = 0
lo = 0
cog = 0
cos = 0
while i < n:
	if s[i] == 'G':
		cog += 1
		while i < n and s[i] != 'S':
			lo += 1
			i += 1
		l.append(('G', lo))
		lo = 0
	if i < n and s[i] == 'S':
		cos += 1
		while i < n and s[i] != 'G':
			lo += 1
			i += 1
		l.append(('S', lo))
		lo = 0
mx = -1
mxg = int()
a = len(l)
if l[0][0] == 'G' and len(l) > 4:
	cos = 2
elif l[0][0] == 'S' and len(l) > 5:
	cos = 2
else:
	cos = 1
for i in range(a):
	if i + 2 < a and l[i][0] == 'G' and (l[i + 1][0] == 'S') and (l[i + 1][1] == 1) and (l[i + 2][0] == 'G'):
		if cos > 1:
			if l[i][1] + 1 + l[i + 2][1] > mx:
				mx = l[i][1] + 1 + l[i + 2][1]
		elif l[i][1] + l[i + 2][1] > mx:
			mx = l[i][1] + l[i + 2][1]
	elif i + 2 < a and l[i][0] == 'G' and (l[i + 1][0] == 'S') and (l[i + 1][1] != 1) and (l[i + 2][0] == 'G'):
		mxg = max(l[i][1] + 1, l[i + 2][1] + 1, mxg)
for i in range(a):
	if l[i][0] == 'G':
		if l[i][1] > mxg:
			mxg = l[i][1]
print(max(mxg, mx))


n = int(input())
string = str(input())
start = 0
end = 0
res = 0
for i in range(len(string)):
	if string[i] == 'G':
		start += 1
	elif string[i] == 'S':
		(start, end) = (0, start)
	res = max(res, start + end + 1)
print(min(res, string.count('G')))


3.5
N = int(input())
A = input()
L = []
cpt = 1
ret = 0
for i in range(1, len(A)):
	if A[i] == A[i - 1]:
		cpt += 1
	else:
		L.append(cpt)
		if A[i] == 'S':
			ret = max(ret, cpt)
		cpt = 1
L.append(cpt)
if A[-1] == 'G':
	ret = max(ret, cpt)
if ret == 0:
	print('0')
	return
if A[0] == 'G':
	cur = True
else:
	cur = False
for i in range(0, len(L)):
	if not cur:
		if L[i] == 1 and (i + 3 < len(L) or i - 3 >= 0):
			new = 1
			if i > 0:
				new += L[i - 1]
			if i < len(L) - 1:
				new += L[i + 1]
			ret = max(ret, new)
		if L[i] == 1 and i > 0 and (i < len(L) - 1):
			ret = max(ret, L[i - 1] + L[i + 1])
		if i > 0 and i + 1 < len(L):
			ret = max(ret, L[i - 1] + 1)
		if i < len(L) - 1 and i - 1 >= 0:
			ret = max(ret, L[i + 1] + 1)
	cur = not cur
print(ret)


import sys
sys.setrecursionlimit(2000)
from collections import Counter

def solution(n, a):
	new_a = []
	summ = 0
	for i in a:
		summ += i
		if i == 0:
			if summ != 0:
				new_a.append(summ)
			new_a.append(i)
			summ = 0
	if summ != 0:
		new_a.append(summ)
	a = new_a
	gind = 0
	golds = {}
	edges = []
	for (ind, val) in enumerate(a):
		if val != 0:
			golds[gind] = val
			gind += 1
		elif ind != 0 and a[ind - 1] != 0 and (ind != len(a) - 1) and (a[ind + 1] != 0):
			edges.append([gind - 1, gind])
	best = 0
	if len(edges) != 0:
		for (ind1, ind2) in edges:
			val = golds[ind1] + golds[ind2]
			if len(golds) > 2:
				val += 1
			best = max(best, val)
	if len(golds) == 0:
		val = 0
	else:
		val = max([val for (key, val) in golds.items()])
		if len(golds) != 1:
			val += 1
	best = max(best, val)
	print(best)
	return best
n = [int(val) for val in input().split()][0]
a = [1 if val == 'G' else 0 for val in input()]
solution(n, a)


l = int(input())
s = list(input())
n = []
ns = []
f = True
for i in s:
	if i == 'G':
		if f:
			n.append(1)
			ns.append(1)
		else:
			n[-1] += 1
			ns[-1] += 1
		f = False
	else:
		f = True
		n.append(0)
if len(ns) == 0:
	print(0)
elif len(ns) == 1:
	print(ns[0])
else:
	mx = 0
	for i in range(1, len(n) - 1):
		if n[i] == 0 and n[i - 1] and n[i + 1]:
			num = n[i - 1] + n[i + 1]
			if len(ns) > 2:
				num += 1
			mx = max(mx, num)
	print(max(mx, max(n) + 1))


n = int(input())
s = input()
n += 1
s += 'S'
a = []
cnt = 0
cG = s.count('G')
for i in range(n):
	if s[i] == 'G':
		cnt += 1
	else:
		a.append(cnt)
		cnt = 0
a.append(cnt)
max_ = 0
j = 0
for i in range(n):
	if s[i] == 'S':
		c = a[j] + a[j + 1]
		if c < cG:
			max_ = max(c + 1, max_)
		if c == cG:
			max_ = max(c, max_)
		j += 1
print(max_)


from math import ceil, sqrt, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
n = ii()
s = si()
s1 = 0
s2 = 0
f = 0
b = []
b1 = 0
for i in s:
	if i == 'G':
		b1 += 1
i = 0
f1 = 0
s1 = 0
for i in range(n):
	if s[i] == 'G':
		if f1 == 0:
			s1 += 1
		else:
			s2 += 1
		f = 1
	if s[i] == 'S' and f:
		if f1 == 0:
			s2 = 0
			f1 = 1
		else:
			b.append(s1 + 1 + s2)
			s1 = s2
			s2 = 0
if f1:
	b.append(s2 + 1 + s1)
else:
	b.append(s1 + 1)
print(min(max(b), b1))


n = int(input())
s = input()
mx = 0
l = 0
start = -1
first = s[0]
x = []
other = {'S': 'G', 'G': 'S'}
sign = {'S': -1, 'G': 1}
for i in range(n):
	if i == n - 1:
		if start != -1 and s[i] == first:
			ln = (n - start) * sign[first]
			x.append(ln)
			break
		elif start != -1 and s[i] != first:
			ln = (n - 1 - start) * sign[first]
			x.append(ln)
			x.append(sign[s[-1]])
			break
		else:
			ln = sign[s[-1]]
			x.append(ln)
			break
	if start == -1 and s[i] == first:
		start = i
	if start != -1 and s[i] != first:
		ln = (i - start) * sign[first]
		x.append(ln)
		start = i
		first = other[first]
pos = list(filter(lambda x: x > 0, x))
mx = max(x)
if len(pos) >= 2:
	mx += 1
for i in range(len(x) - 2):
	if x[i] > 0 and x[i] + x[i + 2] >= mx and (x[i + 1] == -1):
		mx = x[i] + x[i + 2]
		if len(pos) >= 3:
			mx += 1
if mx < 0:
	print(0)
else:
	print(mx)


import os
import sys
from io import BytesIO, IOBase
import math
import itertools
import bisect
import heapq

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	for i in range(2, n + 1):
		if primes[i]:
			for j in range(i + i, n + 1, i):
				primes[j] = False
	p = []
	for i in range(0, n + 1):
		if primes[i]:
			p.append(i)
	return p

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac
n = int(input())
s = input()
i = 0
l = []
ans = 0
gc = 0
while i < n:
	t = countcon(s, i)
	l.append([t, s[i]])
	if s[i] == 'G':
		ans = max(ans, t)
		gc += 1
	i += t
if gc >= 2:
	ans += 1
le = len(l)
for i in range(0, le):
	if l[i][1] == 'G' and i < le - 2 and (l[i + 1][0] == 1):
		if i >= 2 or i + 2 < le - 2:
			ans = max(ans, l[i][0] + l[i + 2][0] + 1)
		else:
			ans = max(ans, l[i][0] + l[i + 2][0])
print(ans)


import math

def main():
	buf = input()
	n = int(buf)
	buf = input()
	row = buf
	beauty = []
	count = 0
	for i in row:
		if i == 'G':
			count += 1
		else:
			beauty.append(count)
			count = 0
	beauty.append(count)
	if len(beauty) == 1:
		print(beauty[0])
		return
	max_adj_beauty = 0
	isolated = True
	for i in range(len(beauty) - 1):
		if beauty[i] + beauty[i + 1] > max_adj_beauty:
			max_adj_beauty = beauty[i] + beauty[i + 1]
			if beauty[i] == 0 or beauty[i + 1] == 0:
				isolated = True
			else:
				isolated = False
	more_than_one_count = 0
	for i in range(len(beauty)):
		if beauty[i] > 0:
			more_than_one_count += 1
	if more_than_one_count > 2 or (isolated and more_than_one_count > 1):
		max_adj_beauty += 1
	print(max_adj_beauty)
main()


n = int(input())
s = input()
if s == 'G' * n:
	print(n)
	exit()
s += 'A'
rle = [('G', 0)]
cnt = 1
for i in range(n):
	if s[i] != s[i + 1]:
		rle.append((s[i], cnt))
		cnt = 1
	else:
		cnt += 1
rle.append(('G', 0))
GS = s.count('G')
ans = 0
for i in range(len(rle)):
	if rle[i][0] == 'S' and rle[i][1] == 1:
		left_G = rle[i - 1][1]
		right_G = rle[i + 1][1]
		if left_G + right_G < GS:
			ans = max(ans, left_G + right_G + 1)
		else:
			ans = max(ans, left_G + right_G)
	elif rle[i][0] == 'G':
		G = rle[i][1]
		if G < GS:
			ans = max(ans, G + 1)
		else:
			ans = max(ans, G)
print(ans)


n = int(input())
s = input()
total = s.count('G')
a = []
c = 0
if total == 0:
	print(0)
elif total == n:
	print(n)
else:
	for i in range(n - 1):
		if s[i] == 'G':
			c += 1
		else:
			if i > 0 and s[i - 1] == 'G':
				a.append(c)
				c = 0
			a.append('S')
	if s[-1] == 'G':
		a.append(c + 1)
	else:
		if s[-2] == 'G':
			a.append(c)
		a.append('S')
	ans = 0
	n = len(a)
	for i in range(n):
		if type(a[i]) == int and i + 2 < n:
			if a[i + 2] == 'S':
				ans = max(ans, min(a[i] + 1, total))
			else:
				ans = max(ans, min(total, a[i] + a[i + 2] + 1))
	for e in [a[-1], a[-2]]:
		if type(e) == int:
			ans = max(ans, min(e + 1, total))
	print(ans)


import math
n = int(input())
a = input()
lens = []
currlen = 1
for i in range(n - 1):
	if a[i + 1] == a[i]:
		currlen += 1
	else:
		lens.append(currlen)
		currlen = 1
lens.append(currlen)
if a[0] == 'G':
	if len(lens) < 3:
		print(lens[0])
	elif len(lens) < 5:
		if lens[1] == 1:
			print(lens[0] + lens[2])
		else:
			print(max(lens[0], lens[2]) + 1)
	else:
		indivbest = 0
		consecbest = 0
		for i in range(math.ceil(len(lens) / 2)):
			indivbest = max(indivbest, lens[2 * i] + 1)
			if i > 0:
				if lens[2 * i - 1] == 1:
					consecbest = max(consecbest, lens[2 * i] + lens[2 * i - 2] + 1)
		print(max(indivbest, consecbest))
elif len(lens) < 2:
	print(0)
elif len(lens) < 4:
	print(lens[1])
elif len(lens) < 6:
	if lens[2] == 1:
		print(lens[1] + lens[3])
	else:
		print(max(lens[1], lens[3]) + 1)
else:
	indivbest = 0
	consecbest = 0
	for i in range(len(lens) // 2):
		indivbest = max(indivbest, lens[2 * i + 1] + 1)
		if i > 0:
			if lens[2 * i] == 1:
				consecbest = max(consecbest, lens[2 * i + 1] + lens[2 * i - 1] + 1)
	print(max(indivbest, consecbest))


(_, string) = (input(), input())
(start, end, res) = (0, 0, 0)
for char in string:
	if char == 'G':
		start += 1
	else:
		end = start
		start = 0
	res = max(res, start + end + 1)
print(min(res, string.count('G')))


n = input()
s = input()
count = 0
maxed = 0
sumed = 0
maxed = 0
c = 0
count = 0
gold = 0
for i in s:
	if i == 'G':
		c += 1
		gold += 1
	else:
		sumed = c
		c = 0
	maxed = max(maxed, sumed + c + 1)
print(min(maxed, gold))


n = int(input())
s = input()
comps = []
comp_size = 0
swaps = [True for _ in range(n)]
s_comp_size = 0
for c in s:
	if c == 'G':
		if s_comp_size > 1:
			swaps[len(comps)] = False
			s_comp_size = 0
		comp_size += 1
	elif comp_size > 0:
		comps.append(comp_size)
		comp_size = 0
		s_comp_size = 1
	else:
		s_comp_size += 1
if comp_size != 0:
	comps.append(comp_size)
if len(comps) == 0:
	print(0)
elif len(comps) == 1:
	print(comps[0])
elif len(comps) > 1:
	ans = 0
	for (i, (c1, c2)) in enumerate(zip(comps[:-1], comps[1:])):
		if swaps[i + 1]:
			ans = max(c1 + c2, ans)
	ans2 = max(comps, default=0) + (len(comps) > 1)
	ans += len(comps) > 2
	print(max(ans, ans2))


n = int(input())
s = input()
res = 0
cg = 0
c = 0
pv = 0
for i in range(0, n):
	if s[i] == 'G':
		cg += 1
		c += 1
	else:
		pv = c
		c = 0
	res = max(res, pv + c + 1)
print(min(res, cg))


n = int(input())
a = input()
start = 0
end = 0
res = 0
for i in a:
	if i == 'G':
		start += 1
	else:
		(end, start) = (start, 0)
	res = max(res, start + end + 1)
print(min(res, a.count('G')))


from sys import stdin

def input():
	return stdin.readline()
n = int(input())
string = input()
take = []
j = 0
counter = 0
count_g = 0
for i in range(n):
	if string[i] == 'G':
		count_g += 1
		if counter == 0:
			counter = 1
			j = i
		elif counter == 1:
			continue
	elif counter == 1:
		counter = 0
		take.append([j, i - 1])
if counter == 1:
	take.append([j, n - 1])
if count_g == 0:
	ans = 0
else:
	ans = take[0][1] - take[0][0] + 1
for i in range(len(take) - 1):
	upper = take[i + 1][1]
	lower = take[i][0]
	if take[i + 1][0] - take[i][1] - 1 == 1:
		if count_g - (upper - lower) > 0:
			ans = max(ans, upper - lower + 1)
		else:
			ans = max(ans, upper - lower)
	else:
		ans = max(ans, take[i][1] - take[i][0] + 2)
		ans = max(ans, take[i + 1][1] - take[i + 1][0] + 2)
print(ans)


import sys
input = sys.stdin.readline
(n, s, count, cnt) = (input(), input(), [], 0)
for i in range(int(n)):
	if s[i] == 'G':
		cnt += 1
	else:
		count.append(cnt)
		cnt = 0
if cnt > 0:
	count.append(cnt)
(ans, ind, f) = (0, -1, False)
for i in range(len(count)):
	if count[i] > 0:
		if ind == -1:
			ind = i
		elif i - ind > 1:
			f = True
			break
for i in range(len(count) - 1):
	ans = max(ans, count[i] + count[i + 1] + f)
print(count[0] if len(count) == 1 else ans)


n = int(input())
a = list(input())
c = 0
prev = 0
m = 0
count = 0
t = 0
for i in range(n):
	if a[i] == 'G':
		count += 1
for i in range(n):
	if a[i] == 'G':
		c += 1
		t = 0
	else:
		t += 1
		if t > 1:
			prev = 0
		elif c + prev > m:
			m = c + prev
		prev = c
		c = 0
if c + prev > m:
	m = c + prev
if count > m:
	m += 1
print(m)


n = int(input())
s = input()
a = []
p = -1
k = 0
for i in range(n):
	if s[i] == 'G':
		if k == 0:
			p = i
		k += 1
	elif k != 0:
		a.append((p, k))
		k = 0
if k != 0:
	a.append((p, k))
max_len = 0
m = len(a)
if m == 1:
	max_len = a[0][1]
elif m > 1:
	max_len = a[0][1]
	exist = False
	for i in range(1, m):
		if a[i][0] - sum(a[i - 1]) == 1:
			max_len = max(max_len, a[i][1] + a[i - 1][1])
			exist = True
		else:
			max_len = max(max_len, a[i][1])
	if exist:
		if m > 2:
			max_len += 1
	else:
		max_len += 1
print(max_len)


n = int(input())
s = input()
pref = [0 for _ in range(n + 1)]
suff = [0 for _ in range(n + 1)]
group = 0
for i in range(0, n):
	if s[i] == 'G':
		if pref[i] == 0:
			group += 1
		pref[i + 1] = 1 + pref[i]
for i in range(n - 1, -1, -1):
	if s[i] == 'G':
		suff[i] = 1 + suff[i + 1]
mxm = max(pref)
if group == 2:
	mxm += 1
	for i in range(0, n):
		if s[i] != 'G':
			mxm = max(mxm, pref[i] + suff[i + 1])
elif group >= 3:
	for i in range(0, n):
		if s[i] != 'G':
			mxm = max(mxm, 1 + pref[i] + suff[i + 1])
print(mxm)


n = int(input())
st = input()
cout = 0
l = 0
r = 0
li = []
for i in range(n):
	if st[i] == 'G':
		r += 1
	else:
		if l != r:
			li.append([l, r - 1])
		l = i + 1
		r = i + 1
if l != r:
	li.append([l, r - 1])
le = len(li)
if le == 0:
	print(0)
elif le == 1:
	print(li[0][1] - li[0][0] + 1)
else:
	if le == 2:
		ans = li[0][1] - li[0][0] + 2
		for i in range(1, le):
			ans = max(ans, li[i][1] - li[i][0] + 2)
			if li[i][0] - li[i - 1][1] == 2:
				ans = max(ans, li[i][1] - li[i - 1][0])
	else:
		ans = li[0][1] - li[0][0] + 2
		for i in range(1, le):
			ans = max(ans, li[i][1] - li[i][0] + 2)
			if li[i][0] - li[i - 1][1] == 2:
				ans = max(ans, li[i][1] - li[i - 1][0] + 1)
	print(ans)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
s = input().strip()
g = []
i = 0
lng = 0
while i < n:
	if s[i] == 'S':
		i += 1
		continue
	j = i + 1
	while j < n and s[j] == 'G':
		j += 1
	g.append((i, j))
	lng = max(lng, j - i)
	i = j + 1
if not g:
	ans = 0
elif len(g) == 1:
	ans = lng
else:
	extra = len(g) > 2
	ans = lng + 1
	for i in range(len(g) - 1):
		(s, e) = g[i]
		(s2, e2) = g[i + 1]
		if s2 != e + 1:
			continue
		ans = max(ans, e - s + e2 - s2 + extra)
print(ans)


(N, S) = (int(input()), input())
(Ranges, Counter) = ([], 0)
for i in range(N):
	if S[i] == 'G':
		Counter += 1
	elif Counter != 0:
		Ranges.append([i - Counter, Counter])
		Counter = 0
if Counter != 0:
	Ranges.append([N - Counter, Counter])
LEN = len(Ranges)
if LEN <= 1:
	print(Ranges[0][1] if LEN == 1 else 0)
elif LEN == 2:
	if Ranges[0][0] + Ranges[0][1] + 1 == Ranges[1][0]:
		print(Ranges[0][1] + Ranges[1][1])
	else:
		print(max(Ranges[0][1], Ranges[1][1]) + 1)
else:
	MaxTotal = Ranges[0][1] + 1
	for i in range(1, LEN):
		MaxTotal = max(MaxTotal, Ranges[i][1] + 1)
		if Ranges[i - 1][0] + Ranges[i - 1][1] + 1 == Ranges[i][0]:
			MaxTotal = max(MaxTotal, Ranges[i - 1][1] + Ranges[i][1] + 1)
	print(MaxTotal)


def longestSubSeg(a, n):
	cnt0 = 0
	l = 0
	max_len = 0
	ctG = 0
	for i in range(0, n):
		if a[i] == 'S':
			cnt0 += 1
		if a[i] == 'G':
			ctG += 1
		while cnt0 > 1:
			if a[l] == 'S':
				cnt0 -= 1
			l += 1
		max_len = max(max_len, i - l + 1)
	if max_len > ctG:
		return max_len - 1
	return max_len
n = int(input())
a = list(input())
print(longestSubSeg(a, n))


def read(type=1):
	if type:
		file = open('input.dat', 'r')
		n = int(file.readline())
		s = file.readline()
		file.close()
	else:
		n = int(input().strip())
		s = input().strip()
	return (n, s)

def solve():
	sol = 0
	tot = 0
	max = 0
	pos = 0
	v = 0
	while pos < n:
		if s[pos] == 'G':
			v += 1
			tot += 1
		else:
			last = v
			if last > max:
				max = last
			v = 0
			if pos != n - 1:
				if s[pos + 1] == 'G':
					pos += 1
					while s[pos] == 'G':
						pos += 1
						v += 1
						tot += 1
						if pos == n:
							break
					if last + v > max:
						max = last + v
					pos -= 1
		pos += 1
	if v > max:
		max = v
	if max == tot:
		max -= 1
	return max + 1
(n, s) = read(0)
sol = solve()
print(sol)


x = int(input())
s = input()
cnts = s.count('S')
cntg = s.count('G')
cnt = 0
mx2 = -55
for i in range(len(s) - 1):
	if s[i] == 'G' and s[i + 1] == 'G':
		cnt += 1
	else:
		cnt = 0
	mx2 = max(cnt, mx2)
mx2 += 1
ls = []
s += '0'
s = '0' + s
for i in range(1, len(s)):
	if s[i - 1] == 'G' and s[i] == 'S' and (s[i + 1] == 'G'):
		ls.append(i)
cnt = 0
mx = -55
for i in range(len(ls)):
	c = ls[i] - 1
	while s[c] == 'G':
		cnt += 1
		c -= 1
	c = ls[i] + 1
	while s[c] == 'G':
		cnt += 1
		c += 1
	mx = max(cnt, mx)
	cnt = 0
maxx = max(mx, mx2)
if cntg == 0:
	print(0)
elif cntg > maxx and cnts > 0:
	print(maxx + 1)
else:
	print(maxx)


n = input()
s = input()
s += 'S'
(bef, now, tot, res) = (0, 0, 0, 0)
for c in s:
	if c == 'G':
		tot = tot + 1
		now = now + 1
	else:
		res = max(res, now + bef + 1)
		bef = now
		now = 0
res = min(tot, res)
print(res)


n = int(input())
s = str(input())
start = 0
end = 0
ans = 0
for i in range(len(s)):
	if s[i] == 'G':
		start += 1
	elif s[i] == 'S':
		(start, end) = (0, start)
	ans = max(ans, start + end + 1)
print(min(ans, s.count('G')))


n = int(input())
a = ['S'] + list(input()) + ['S']
mus = [0] * (n + 2)
piv = 0
suf = 0
g = a.count('G')
for i in range(n + 2):
	if a[i] == 'G':
		suf += 1
		continue
	mus[i] += suf
	mus[piv] += suf
	piv = i
	suf = 0
mus.sort(reverse=True)
if g == n:
	print(g)
	exit()
for i in range(n):
	if g - mus[i] >= 1:
		print(mus[i] + 1)
		exit()
	if g - mus[i] == 0:
		print(mus[i])
		exit()


import math
n = int(input())
s = input()
l = [0]
prev = 'G'
for i in range(n):
	if s[i] == prev:
		l[-1] += 1
	else:
		prev = s[i]
		l.append(1)
ans = 0
h = s.count('G')
for i in range(0, len(l), 2):
	if l[i] != h:
		ans = max(ans, l[i] + 1)
	else:
		ans = max(ans, l[i])
gg = []
for i in range(0, len(l) - 2, 2):
	if l[i + 1] == 1:
		gg.append([l[i], l[i + 2]])
for i in gg:
	if sum(i) != h:
		ans = max(ans, sum(i) + 1)
	else:
		ans = max(ans, sum(i))
print(ans)


from sys import stdin, stdout
import math
N = int(input())
s = input()
g = 0
golden = [0] * N
idx = []
for i in range(N):
	if s[i] == 'S':
		idx.append(i)
	else:
		g += 1
	golden[i] = g
if len(idx) == 0:
	print(N)
	quit()
elif len(idx) == 1:
	print(N - 1)
	quit()
res = 0
for i in range(1, len(idx)):
	if i == 1:
		L = 0
		R = idx[i]
		if golden[R - 1] == g:
			res = max(res, g)
		else:
			res = max(res, golden[R - 1] + 1)
	else:
		L = idx[i - 2]
		R = idx[i]
		if golden[R - 1] - golden[L] == g:
			res = max(res, g)
		else:
			res = max(res, golden[R - 1] - golden[L] + 1)
L = idx[-2]
R = N
if golden[R - 1] - golden[L] == g:
	res = max(res, g)
else:
	res = max(res, golden[R - 1] - golden[L] + 1)
print(res)


n = int(input())
t = input()
L = [-1]
s = 0
for i in range(n):
	if t[i] == 'S':
		L.append(i)
		s += 1
L.append(n)
m = L[1] - L[0] - 1
for i in range(len(L) - 2):
	if L[i + 2] - L[i] - 1 > m:
		m = L[i + 2] - L[i] - 1
print(min(m, n - s))


for _ in range(1):
	n = int(input())
	st = input()
	if st[0] == 'S':
		n += 1
		st = 'S' + st
	if st[-1] == 'S':
		n += 1
		st = st + 'S'
	g = []
	s = []
	add = 1
	st = st + '6'
	for i in range(n):
		if st[i] == st[i + 1]:
			add += 1
		else:
			if st[i] == 'G':
				g.append(add)
			else:
				s.append(add)
			add = 1
	if len(g) == 0:
		print(0)
		continue
	if len(g) == 1:
		print(g[0])
		continue
	if len(g) == 2 and s.count(1) >= 1:
		print(g[0] + g[1])
		continue
	if st[0] == 'S':
		g = [0] + g
	if st[-2] == 'S':
		g.append(0)
	l_s = len(s)
	maxi = 0
	for i in range(l_s):
		if s[i] == 1:
			maxi = max(maxi, g[i] + g[i + 1] + 1)
		else:
			maxi = max(maxi, g[i] + 1, g[i + 1] + 1)
	print(maxi)


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]
n = read_int()
s = read_line()
a = [0] * n
for i in range(n):
	if s[i] == 'G':
		a[i] = 1
s = s.split('S')
st = []
for i in s:
	if len(i) > 0:
		st.append(i)
l = [0] * n
r = [0] * n
if a[0] == 1:
	l[0] = 1
for i in range(1, n):
	if a[i] == a[i - 1] and a[i] == 1:
		l[i] = l[i - 1] + 1
	elif a[i] != a[i - 1] and a[i - 1] == 0:
		l[i] = 1
	else:
		l[i] = 0
if a[n - 1] == 1:
	r[n - 1] = 1
for i in range(n - 2, -1, -1):
	if a[i] == a[i + 1] and a[i] == 1:
		r[i] = r[i + 1] + 1
	elif a[i] != a[i + 1] and a[i + 1] == 0:
		r[i] = 1
	else:
		r[i] = 0
cnt = a.count(1)
ans = 0
if cnt != 0:
	ans = len(st[0])
for i in range(1, n - 1):
	if l[i - 1] + r[i + 1] < cnt:
		ans = max(ans, l[i - 1] + r[i + 1] + 1)
	else:
		ans = max(ans, l[i - 1] + r[i + 1])
print(ans)


n = int(input())
s = input()
gold = []
start = 0
end = 0
flag = False
mxx = -1
for i in range(n):
	if s[i] == 'G':
		if not flag:
			flag = True
			start = i
			end = i
		end += 1
	if s[i] != 'G' and flag:
		flag = False
		gold.append((start, end))
		mxx = max(mxx, end - start)
if flag:
	gold.append((start, end))
	mxx = max(mxx, end - start)
mx = -1
size = lambda a: a[1] - a[0]
for i in range(len(gold) - 1):
	if gold[i + 1][0] - gold[i][1] == 1:
		if len(gold) > 2:
			mx = max(mx, size(gold[i]) + size(gold[i + 1]) + 1)
		else:
			mx = max(mx, size(gold[i]) + size(gold[i + 1]))
if len(gold) > 1:
	mxx += 1
print(max(mx, mxx, 0))


def solve():
	n = int(input())
	s = input()
	l = []
	(g_seg, s_seg) = (0, 0)
	g_count = 0
	for i in range(n):
		if s[i] == 'S':
			if g_seg:
				g_count += 1
				l.append(('G', g_seg))
				g_seg = 0
			s_seg += 1
		else:
			if s_seg:
				l.append(('S', s_seg))
				s_seg = 0
			g_seg += 1
	if g_seg:
		l.append(('G', g_seg))
		g_count += 1
	if not g_count:
		return 0
	if len(l) == 1:
		return l[0][1]
	elif len(l) == 2:
		return l[1][1]
	if g_count == 2:
		ans = 0
		for i in range(len(l) - 2):
			if l[i][0] == 'G':
				if l[i + 1][1] == 1:
					ans = max(ans, l[i][1] + l[i + 2][1])
				else:
					ans = max(ans, l[i][1] + 1, l[i + 2][1] + 1)
		return ans
	else:
		ans = 0
		for i in range(len(l) - 2):
			if l[i][0] == 'G':
				if l[i + 1][1] == 1:
					ans = max(ans, l[i][1] + 1 + l[i + 2][1])
				else:
					ans = max(ans, l[i][1] + 1, l[i + 2][1] + 1)
		return ans
print(solve())


(n, s) = (int(input()), input())
(start, end, ans) = (0, 0, 0)
for i in s:
	if i == 'G':
		start += 1
	else:
		(end, start) = (start, 0)
	ans = max(ans, start + end + 1)
print(min(ans, s.count('G')))


n = int(input())
a = b = c = ret = 0
for i in input():
	if i == 'G':
		a += 1
		c += 1
	else:
		b = c
		c = 0
	ret = max(ret, b + c + 1)
print(min(ret, a))


n = int(input())
s = input()
max_ans = len([x for x in s if x == 'G'])
right = 0
cnt = 0
ans = 0
for i in range(n):
	assigned = False
	for j in range(right, n, 1):
		if s[j] == 'S':
			cnt += 1
		if cnt > 1:
			right = j
			cnt -= 1
			assigned = True
			break
	if not assigned:
		right = n
	ans = max(ans, right - i)
	if s[i] == 'S':
		cnt -= 1
ans = min(ans, max_ans)
print(ans)


n = int(input())
ss = input()
if ss.count('S') == 0:
	print(len(ss))
elif ss.count('G') == 0:
	print(0)
else:
	x = 0
	y = 0
	s = 0
	g = 0
	ans = 0
	while x <= y and y < len(ss):
		if s < 2:
			if ss[y] == 'G':
				g += 1
			else:
				s += 1
			y += 1
			if s < 2 and ans < y - x:
				if s == 0:
					ans = g
				elif ss.count('G') > g:
					ans = g + 1
		else:
			if ss[x] == 'G':
				g -= 1
			else:
				s -= 1
			x += 1
	print(ans)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	global n, a
	n = int(stdin.readline())
	a = ' ' + stdin.readline().replace('\n', '') + ' '
	L = [0] * len(a)
	R = [0] * len(a)
	maxL = [0] * len(a)
	maxR = [0] * len(a)
	res = 0
	for i in range(1, len(a)):
		if a[i] == 'G':
			L[i] = L[i - 1] + 1
		maxL[i] = max(maxL[i - 1], L[i])
		res = max(res, L[i])
	if res == 0:
		stdout.write(str(res))
		return 0
	i = len(a) - 2
	while i >= 0:
		if a[i] == 'G':
			R[i] = R[i + 1] + 1
		maxR[i] = max(maxR[i + 1], R[i])
		i = i - 1
	for i in range(len(a) - 1):
		if a[i] == 'S':
			res = max(L[i - 1] + R[i + 1], res)
			if maxL[i - 1 - L[i - 1]] + maxR[i + 1 + R[i + 1]] > 0:
				res = max(res, L[i - 1] + R[i + 1] + 1)
	stdout.write(str(res))
	return 0
main()


def solve():
	n = int(input())
	s = input()
	j = 0
	d = []
	for i in range(n):
		if s[i] == 'G':
			j += 1
		elif i and j:
			d.append((i - j, i - 1))
			j = 0
	if j:
		d.append((i - j + 1, i - 1 + 1))
	m = 0
	for i in range(len(d)):
		m = max(m, d[i][1] - d[i][0] + 1 + int(len(d) > 1))
		if i > 0 and d[i][0] - 2 == d[i - 1][1]:
			m = max(m, d[i][1] - d[i - 1][0] + 1 - int(len(d) == 2))
	return m
print(solve())


def getArr(s, n):
	Gind = 0
	arr = []
	temp = ''
	temp += s[0]
	for i in range(1, n):
		curr = s[i]
		if curr == s[i - 1]:
			temp += s[i]
		else:
			arr.append((s[i - 1], len(temp)))
			temp = curr
			if s[i - 1] == 'G':
				Gind += 1
			i += 1
	if len(temp) > 0:
		arr.append((temp[0], len(temp)))
		if temp[0] == 'G':
			Gind += 1
	return (arr, Gind)

def solve(arr, Gind):
	ans = 0
	hasG = False
	maxG = 0
	for i in range(len(arr)):
		tempMax = 0
		if arr[i][0] == 'S':
			if arr[i][1] > 1:
				(le, ri) = (0, 0)
				if i - 1 >= 0:
					le = arr[i - 1][1]
				if i + 1 < len(arr):
					ri = arr[i + 1][1]
				tempMax = max(le, ri)
				if Gind > 1:
					tempMax += 1
				if tempMax > ans:
					ans = tempMax
			else:
				(lef, rig) = (0, 0)
				if i - 1 >= 0:
					lef = arr[i - 1][1]
				if i + 1 < len(arr):
					rig = arr[i + 1][1]
				tempMax = lef + rig
				if Gind > 2:
					tempMax += 1
				if tempMax > ans:
					ans = tempMax
		else:
			hasG = True
			maxG = max(maxG, arr[i][1])
	if ans == 0 and hasG:
		print(maxG)
	else:
		print(ans)

def run():
	n = int(input())
	s = input()
	(arr, gind) = getArr(s, n)
	solve(arr, gind)
run()


n = int(input())
s = input()
if s.count('G') == n:
	print(n)
	exit()
if s.count('G') == 0:
	print(0)
	exit()
cnt = 0
k = 1
i = 0
j = 0
maxi = -1
while j < n:
	if s[j] == 'S':
		cnt += 1
	while cnt > k:
		cnt -= s[i] == 'S'
		i += 1
	maxi = max(maxi, j - i + 1)
	j += 1
print(min(maxi, s.count('G')))


n = int(input())
w = input()
zc = w[0]
sl = zs = 0
s = list()
for i in range(0, n):
	if w[i] == zc and i < n - 1:
		sl += 1
	elif i == n - 1:
		if w[i] == zc:
			sl += 1
			if w[i] == 'S':
				sl *= -1
			s.append(sl)
		else:
			if w[i - 1] == 'S':
				sl *= -1
			s.append(sl)
			sl = 1
			if w[i] == 'S':
				sl *= -1
			s.append(sl)
	else:
		if w[i - 1] == 'S':
			sl *= -1
		s.append(sl)
		sl = 1
		zc = w[i]
zc = sl = 0
for i in range(0, len(s)):
	if s[i] > 0:
		zs += 1
if zs <= 2:
	if zs <= 1:
		for i in range(0, len(s)):
			if s[i] > 0:
				sl = s[i]
				break
		print(sl)
	else:
		for i in range(0, len(s)):
			if zc == 0 and s[i] < 0:
				continue
			if s[i] > 0:
				if zc > 0:
					if s[i - 1] >= -1:
						sl = max(sl, zc + s[i])
					else:
						sl = max(sl, zc + 1)
				zc = s[i]
		sl = max(zc + 1, sl)
		print(sl)
else:
	for i in range(0, len(s)):
		if zc == 0 and s[i] < 0:
			continue
		if s[i] > 0:
			if zc > 0:
				if s[i - 1] >= -1:
					sl = max(sl, zc + s[i] + 1)
				else:
					sl = max(sl, zc + 1)
			zc = s[i]
	sl = max(zc + 1, sl)
	print(sl)


while True:
	try:
		n = int(input())
		s = input()
		prv = 0
		flag = False
		Max = -1000
		lan = cnt = 0
		gold = 0
		got = False
		for i in range(n):
			if s[i] == 'G':
				if cnt > 1:
					prv = 0
				if cnt == 1 and gold > 0:
					got = True
				lan += 1
				Max = max(prv + lan, Max)
				flag = True
				cnt = 0
			else:
				cnt += 1
				if flag:
					gold += 1
					prv = lan
					flag = False
				lan = 0
		if flag:
			gold += 1
		if gold > 1 and (not got):
			print(Max + 1)
		elif gold > 2:
			print(Max + 1)
		elif gold == 0:
			print(0)
		else:
			print(Max)
	except EOFError:
		break


n = int(input())
s = 'S' + input() + 'S'
l = []
for (i, c) in enumerate(s):
	if c == 'S':
		l += [i]
gCount = s.count('G')
if len(l) == 2:
	print(len(s) - 2)
else:
	ans = 0
	for i in range(len(l) - 2):
		ans = max(ans, l[i + 2] - l[i] - 1 if l[i + 2] - l[i] - 1 <= gCount else l[i + 2] - l[i] - 2)
	print(ans)


input()
res = 0
cur = 1
cur_p = 0
s = input()
for c in s:
	if c == 'G':
		cur += 1
		cur_p += 1
		res = max(res, cur)
	else:
		cur = cur_p + 1
		cur_p = 0
print(min(res, s.count('G')))


n = int(input())
t = input()
t += 'S'
ans = cnt = pre = ttl = 0
for i in t:
	if i == 'G':
		cnt += 1
		ttl += 1
	else:
		ans = max(ans, cnt + pre + 1)
		pre = cnt
		cnt = 0
print(min(ttl, ans))


import sys, math, queue
MOD = 998244353
sys.setrecursionlimit(1000000)
n = int(input())
s = input()
g = [0]
for si in s:
	if si == 'S':
		g.append(0)
	elif si == 'G':
		g[-1] += 1
nz = len(g) - g.count(0)
ans = max(g)
for i in range(1, len(g)):
	a = g[i] + g[i - 1]
	if nz > 2:
		a += 1
	elif nz == 2:
		if g[i] == 0 or g[i - 1] == 0:
			a = max(g[i], g[i - 1]) + 1
		else:
			a = g[i] + g[i - 1]
	elif nz == 1:
		a = max(g[i], g[i - 1])
	ans = max(ans, a)
print(ans)


n = int(input())
c = [0 if x == 'G' else 1 for x in input().strip()]
gc = c.count(0)
sc = c.count(1)
if n <= 5 or sc <= 1 or gc <= 2:
	mgl = gc
else:
	lclb = []
	ocl = False
	pclb = -1
	for i in range(n):
		if ocl:
			if c[i] == 1:
				ocl = False
				cle = i - 1
				cll = cle - cls + 1
				clb = i
				lclb.append([clb, cll])
				if pclb >= 0:
					lclb.append([pclb, cll])
			elif i == n - 1:
				cle = i
				cll = cle - cls + 1
				if pclb >= 0:
					lclb.append([pclb, cll])
		elif c[i] == 0:
			ocl = True
			cls = i
			if cls - 1 >= 0:
				pclb = cls - 1
			if i == n - 1:
				cle = i
				cll = cle - cls + 1
				if pclb >= 0:
					lclb.append([pclb, cll])
	lclb.sort(key=lambda x: x[0])
	mgl = -1
	for i in range(len(lclb)):
		mgl = max(mgl, lclb[i][1])
		if i > 0:
			if lclb[i][0] == lclb[i - 1][0]:
				mgl = max(mgl, lclb[i][1] + lclb[i - 1][1])
	if mgl < gc:
		mgl += 1
print(mgl)


n = input()
tropies = input()

def max_gold(tropies):
	gold_count = 0
	last_move = last_no_move = 0
	max_count = 0
	for i in range(len(tropies)):
		if i == 0:
			if tropies[i] == 'G':
				move = no_move = 1
				gold_count += 1
			else:
				move = 1
				no_move = 0
		elif tropies[i] == 'G':
			move = last_move + 1
			no_move = last_no_move + 1
			gold_count += 1
		else:
			move = last_no_move + 1
			no_move = 0
		max_count = max(max_count, move, no_move)
		(last_move, last_no_move) = (move, no_move)
	return min(max_count, gold_count)
print(max_gold(tropies))


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	from itertools import groupby
	n = int(input())
	s = [(key, len(list(value))) for (key, value) in groupby(input().rstrip())]
	g_cnt = sum((x for (c, x) in s if c == 'G'))
	ans = max((x for (c, x) in s if c == 'G'), default=0)
	if s[0][0] == 'G':
		s.insert(0, ('S', 0))
	if s[-1][0] == 'G':
		s.append(('S', 0))
	for i in range(1, len(s) - 1):
		if s[i][0] == 'G':
			continue
		if s[i][1] == 1:
			ans = max(ans, s[i - 1][1] + s[i + 1][1] + (1 if g_cnt > s[i - 1][1] + s[i + 1][1] else 0))
		else:
			ans = max(ans, max(s[i - 1][1], s[i + 1][1]) + 1)
	print(ans)
main()


n = int(input())
s = 'S' + input().strip() + 'S'
(L, R, G) = ([], [], 0)
for i in range(n + 1):
	if s[i] == 'G':
		G += 1
	if s[i] == 'S' and s[i + 1] == 'G':
		L.append(i + 1)
	if s[i] == 'G' and s[i + 1] == 'S':
		R.append(i)
M = 0
for i in range(len(L)):
	if G > R[i] - L[i] + 1:
		M = max(M, R[i] - L[i] + 2)
	else:
		M = max(M, R[i] - L[i] + 1)
for i in range(len(L) - 1):
	if L[i + 1] == R[i] + 2:
		if G > R[i + 1] - L[i]:
			M = max(M, R[i + 1] - L[i] + 1)
		else:
			M = max(M, R[i + 1] - L[i])
print(M)


n = int(input())
seq = input().replace(' ', '')
nGTotal = seq.count('G')
nGCur = 0
right = -1
result = 0
for left in range(n):
	if right < left:
		right = left - 1
		nGCur = 0
	while right + 1 < n and (seq[right + 1] == 'G' and (right - left + 1 - nGCur == 0 or nGCur + 2 <= nGTotal) or (seq[right + 1] == 'S' and right + 1 - left + 1 - nGCur <= 1 and (nGCur + 1 <= nGTotal))):
		right += 1
		if seq[right] == 'G':
			nGCur += 1
	result = max(right - left + 1, result)
	if seq[left] == 'G':
		assert right >= left
		nGCur -= 1
print(result)


n = int(input())
s = list(input())
(ini, end) = ([0] * n, [0] * n)
cntG = 0
for i in range(n):
	if s[i] == 'G':
		cntG += 1
		end[i] = 1
		if i > 0:
			end[i] += end[i - 1]
	j = n - i - 1
	if s[j] == 'G':
		ini[j] = 1
		if j < n - 1:
			ini[j] += ini[j + 1]
res = max(end)
for i in range(n):
	if end[i] == 0 and i > 0 and (i < n - 1):
		res = max(end[i - 1] + ini[i + 1], res)
if res == 0:
	print(0)
elif res < cntG:
	print(res + 1)
else:
	print(res)


n = int(input())
s = input() + 'SS'
d = []
silv = 0
gold = 0
l = []
for c in s:
	if c == 'G':
		gold += 1
		silv = 0
	else:
		silv += 1
		if silv > 1 and len(l) > 0:
			d.append(l)
			l = []
		if gold > 0:
			l.append(gold)
		gold = 0
if len(d) == 0:
	print(0)
elif len(d) == 1:
	l = d[0]
	if len(l) == 1:
		print(l[0])
	elif len(l) == 2:
		print(sum(l))
	else:
		m = 0
		last = 0
		for i in l:
			m = max(m, last + i + 1)
			last = i
		print(m)
else:
	m = 0
	for l in d:
		last = 0
		for i in l:
			m = max(m, last + i + 1)
			last = i
	print(m)


n = int(input())
lst = input()
su = []
maxi = 0
g = 0
for i in range(n):
	if i == 0 and lst[i] == 'G':
		su.append(1)
		g += 1
	elif i == 0 and lst[i] == 'S':
		su.append(0)
	elif lst[i] == 'G':
		su.append(su[i - 1] + 1)
		maxi = max(maxi, su[i])
		g += 1
	elif lst[i] == 'S':
		su.append(0)
e = ''
for i in range(n):
	if su[i] == 0:
		e += '-'
	else:
		e += '/' + str(su[i])
lst = e.split('-')
r = []
q = []
w = []
for i in range(len(lst) - 1):
	if lst[i] != '' or lst[i + 1] != '':
		if lst[i] != '':
			q = lst[i].split('/')
		else:
			q.append(0)
		if lst[i + 1] != '':
			w = lst[i + 1].split('/')
		else:
			w.append(0)
		a = int(q[-1])
		b = int(w[-1])
		r.append(a + b)
if not r:
	if g > maxi:
		print(maxi + 1)
	else:
		print(maxi)
else:
	r.sort()
	if r[-1] < g:
		print(r[-1] + 1)
	else:
		print(r[-1])


n = int(input())
s = list(input())
(l, r) = ([0] * len(s), [0] * len(s))
for i in range(len(s) - 1, -1, -1):
	if s[i] == 'G':
		if i == len(s) - 1:
			r[i] = 1
		else:
			r[i] += r[i + 1] + 1
for i in range(len(s)):
	if s[i] == 'G':
		if i == 0:
			l[i] = 1
		else:
			l[i] += l[i - 1] + 1
ans = 0
for i in range(len(s)):
	if s[i] == 'S':
		tmp = 1
		if i == 0:
			tmp += r[i + 1]
		elif i == len(s) - 1:
			tmp += l[i - 1]
		else:
			tmp += l[i - 1] + r[i + 1]
		ans = max(ans, tmp)
g_num = 0
for c in s:
	if c == 'G':
		g_num += 1
ans = min(ans, g_num)
if g_num == n:
	ans = n
print(ans)


n = int(input())
s = input()
segm = []
segmx = 0
x = -1
g = 0
for i in range(n):
	if s[i] == 'G':
		if x == -1:
			x = i
		g += 1
	elif s[i] == 'S' and -1 < x:
		segm.append([x, i])
		segmx = max(segmx, i - x)
		x = -1
if -1 < x:
	segm.append([x, n])
	segmx = max(segmx, n - x)
if segmx < g:
	segmx += 1
for i in range(len(segm) - 1):
	if segm[i][1] + 1 == segm[i + 1][0]:
		l = segm[i + 1][1] - segm[i][0]
		if l == n or g < l:
			segmx = l - 1
			break
		else:
			segmx = max(segmx, l)
print(segmx)


input()
g = 0
pre = 0
c = 0
ans = 0
for ch in input():
	if ch == 'G':
		g += 1
		c += 1
	else:
		pre = c
		c = 0
	ans = max(ans, pre + c + 1)
print(min(ans, g))


n = int(input())
S = input()
(L, R) = ([0] * (n + 1), [0] * (n + 1))
for i in range(n):
	if S[i] == 'G':
		L[i] = 1 + L[i - 1]
for i in range(n - 1, -1, -1):
	if S[i] == 'G':
		R[i] = 1 + R[i + 1]
res = 0
cntG = S.count('G')
for i in range(n):
	if S[i] == 'G':
		continue
	nres = L[i - 1] + 1 + R[i + 1]
	if res < nres:
		res = min(nres, cntG)
if res == 0:
	res = cntG
print(res)


import math
import collections
import bisect
import heapq
import time
import itertools
import sys
N = int(input())
A = input()
i = 0
segs = []
while i < N:
	if A[i] == 'G':
		j = i + 1
		while j < N and A[j] == 'G':
			j += 1
		segs.append((i, j))
		i = j
	else:
		i += 1

def seglen(seg):
	return seg[1] - seg[0]
ans = 0
if not segs:
	pass
elif len(segs) == 1:
	ans = seglen(segs[0])
elif len(segs) == 2:
	if segs[1][0] == segs[0][1] + 1:
		ans = seglen(segs[0]) + seglen(segs[1])
	else:
		ans = max([seglen(x) for x in segs]) + 1
else:
	ans = max([seglen(x) for x in segs]) + 1
	for i in range(len(segs) - 1):
		if segs[i][1] + 1 == segs[i + 1][0]:
			ans = max(ans, seglen(segs[i]) + seglen(segs[i + 1]) + 1)
print(ans)


n = int(input())
s = input()
p1 = 0
p2 = 0
maxnum = 0
ans = 0
for c in s:
	if c == 'G':
		p1 = p1 + 1
		maxnum = maxnum + 1
	else:
		p1 = p1 + 1
		p2 = p1
		p1 = 0
	t = p1 + p2
	ans = max(ans, t)
ans = min(ans, maxnum)
print(ans)


n = int(input())
s = input()
s1 = s.split('S')
s2 = [x for x in s1 if len(x) > 0]
c = len(s2)
res = 0
if c == 0:
	pass
elif c == 1:
	res = len(s2[0])
else:
	res = len(max(s2, key=lambda x: len(x))) + 1
	r = 1 if c > 2 else 0
	for i in range(1, len(s1)):
		if s1[i] != '' and s1[i - 1] != '':
			res = max(res, len(s1[i]) + len(s1[i - 1]) + r)
print(res)


n = int(input())
s = str(input())
X = []
cur = s[0]
cnt = 0
ans = 0
for i in range(n):
	if s[i] == cur:
		cnt += 1
	else:
		if cur == 'G':
			ans = max(cnt, ans)
		X.append((cnt, cur))
		cur = s[i]
		cnt = 1
else:
	if cur == 'G':
		ans = max(cnt, ans)
	X.append((cnt, cur))
m = len(X)
if m <= 2:
	print(ans)
	exit()
for (i, (cnt, c)) in enumerate(X):
	if c == 'G':
		continue
	if cnt == 1:
		if i != 0 and i != m - 1:
			if i - 3 >= 0 or i + 3 <= m - 1:
				ans = max(ans, X[i - 1][0] + 1 + X[i + 1][0])
			else:
				ans = max(ans, X[i - 1][0] + X[i + 1][0])
		elif i == 0:
			if i + 3 <= m - 1:
				ans = max(ans, 1 + X[i + 1][0])
			else:
				ans = max(ans, X[i + 1][0])
		elif i - 3 >= 0:
			ans = max(ans, X[i - 1][0])
		else:
			ans = max(ans, X[i - 1][0])
	elif i != 0 and i != m - 1:
		ans = max(ans, max(1 + X[i - 1][0], 1 + X[i + 1][0]))
	elif i == 0:
		if i + 3 <= m - 1:
			ans = max(ans, 1 + X[i + 1][0])
		else:
			ans = max(ans, X[i + 1][0])
	elif i - 3 >= 0:
		ans = max(ans, X[i - 1][0] + 1)
	else:
		ans = max(ans, X[i - 1][0])
print(ans)


n = int(input())
s = str(input())
a = []
a.append(0)
i = 0
countmax = 0
piece = 0
flag = 0
while i < n:
	if s[i] == 'S':
		a.append(i + 1)
	i += 1
a.append(n + 1)
l = len(a)
if l == 2:
	print(n)
else:
	for j in range(1, l - 1):
		count = a[j] - a[j - 1] - 1 + a[j + 1] - a[j] - 1
		if count >= countmax:
			countmax = count
		if a[j] - a[j - 1] > 1:
			piece += 1
	if a[l - 1] - a[l - 2] > 1:
		piece += 1
	if piece > 2:
		countmax += 1
	if piece == 2:
		for k in range(1, l - 1):
			if a[k] - a[k - 1] > 1 and a[k + 1] - a[k] > 1:
				flag = 1
		if flag == 0:
			countmax += 1
	print(countmax)


n = int(input())
s = input().rstrip()
x = list(s)
t = 0
l = []
q = []
O = 0
G = 0
V = 0
for i in range(0, len(x)):
	if x[i] == 'S':
		if O == 0:
			O = 1
			l.append(t)
			t = 0
		else:
			q.append(t)
			l.append(t)
			t = 0
	else:
		G = 2
		t += 1
		V += 1
q.append(t)
if len(l) == 0:
	print(q[0])
elif G != 2:
	print(0)
else:
	T = -111111111111111111111
	for i in range(0, len(l)):
		A = l[i] + q[i]
		if A < V:
			T = max(T, l[i] + q[i] + 1)
		else:
			T = max(T, l[i] + q[i])
	print(T)


n = int(input())
s = input()
(mas, q, k, l, res, b) = ([], s[0], '', -1, 0, 0)
for (i, x) in enumerate(s):
	if x == k:
		mas[l] += 1
	else:
		mas.append(1)
		k = x
		if x == 'G':
			b += 1
		l += 1
a = len(mas)
if a == 1:
	if q == 'G':
		print(n)
	else:
		print(0)
elif a == 2:
	if q == 'G':
		print(mas[0])
	else:
		print(mas[1])
else:
	for (i, x) in enumerate(mas):
		if q == 'G':
			(j, f) = (i - 1, i - 2)
			if f > -1:
				if mas[j] == 1:
					if b > 2:
						p = mas[f] + mas[i] + 1
					else:
						p = mas[f] + mas[i]
					if res < p:
						res = p
				else:
					p = mas[i] + 1
					if res < p:
						res = p
			(j, f) = (i + 1, i + 2)
			if f < a:
				if mas[j] == 1:
					if b > 2:
						p = mas[f] + mas[i] + 1
					else:
						p = mas[f] + mas[i]
					if res < p:
						res = p
				else:
					p = mas[i] + 1
					if res < p:
						res = p
			q = 'S'
		else:
			q = 'G'
	if res == 0:
		if b == 1:
			res = s.count('G')
	print(res)


n = int(input())
s = input()
(c, p) = (0, 0)
res = 0
for i in range(n):
	if s[i] == 'G':
		c += 1
	else:
		p = c
		c = 0
	res = max(res, p + c + 1)
print(min(res, s.count('G')))


import sys
n = int(input())
TR = 's' + input() + 'S' + 'S'
LIST = []
NOW = 0
for i in range(1, n + 2):
	if TR[i] == 'G':
		NOW += 1
	elif NOW > 0:
		LIST.append(NOW)
		NOW = 0
		if TR[i + 1] == 'G':
			LIST.append('+')
if len(LIST) == 0:
	print(0)
	sys.exit()
ANS = 0
check = 0
for i in range(len(LIST)):
	if LIST[i] != '+':
		if LIST[i] > ANS:
			ANS = LIST[i]
			check = 0
	elif LIST[i - 1] + LIST[i + 1] >= ANS:
		ANS = LIST[i - 1] + LIST[i + 1]
		check = 1
GMAX = TR.count('G')
print(min(GMAX, ANS + 1))


(n, line) = (int(input()), input())
line2 = [True if l != 'G' else False for l in line]
Sindices = [-1]
Sindices.extend([i for i in range(n) if line2[i]])
Gindices = [i for i in range(n) if not line2[i]]
Sindices.append(n)
segs = []
s = Gindices[0] if len(Gindices) > 0 else -1
for i in range(1, len(Gindices)):
	if Gindices[i - 1] != Gindices[i] - 1:
		segs.append((s, Gindices[i - 1]))
		s = Gindices[i]
if s != -1 and (len(segs) > 0 and segs[-1][0] != s or len(segs) == 0):
	segs.append((s, Gindices[-1]))
if len(segs) == 0:
	print(0)
elif len(segs) == 1:
	print(len(Gindices))
elif len(segs) == 2:
	if segs[0][1] + 2 == segs[1][0]:
		print(len(Gindices))
	else:
		print(max(segs[0][1] - segs[0][0], segs[1][1] - segs[1][0]) + 2)
else:
	maxii = 0
	maxi = segs[0][1] - segs[0][0]
	for i in range(1, len(segs)):
		v = segs[i][1] - segs[i][0]
		if v > maxi:
			maxi = v
		if segs[i - 1][1] + 2 == segs[i][0]:
			v = segs[i][1] - segs[i - 1][0]
			if v > maxii:
				maxii = v
	print(max(maxi + 1, maxii) + 1)


n = int(input())
l = [0] * (n + 1)
r = [0] * (n + 1)
s = input().strip()
(c1, c2) = (0, 0)
(msf, mi) = (-1, -1)
for i in range(len(s)):
	if s[i] == 'G':
		c1 += 1
		l[i] = -1
	else:
		l[i] = c1
		c1 = 0
	if s[n - i - 1] == 'G':
		c2 += 1
		r[n - i - 1] = -1
	else:
		r[n - i - 1] = c2
		c2 = 0
for i in range(len(s)):
	if msf < l[i] + r[i]:
		msf = l[i] + r[i]
		mi = i
if msf == -1:
	print(n)
else:
	ans = msf
	if s.count('G') > ans:
		ans += 1
	print(ans)


n = int(input())
s = input()
l = []
i = res = c = 0
while i < n:
	g = 0
	while i < n and s[i] == 'G':
		i += 1
		g += 1
	l.append(g)
	res = max(res, g)
	if g > 0:
		c += 1
	g = 0
	while i < n and s[i] == 'S':
		i += 1
		g += 1
	l.append(g)
if c > 1:
	res += 1
for i in range(0, len(l) - 2, 2):
	if l[i + 1] == 1:
		res = max(res, l[i] + l[i + 2] + (1 if c >= 3 else 0))
print(res)


n = int(input())
a = list(input())
ans = 0
c = 0
for i in range(n):
	if a[i] == 'G':
		c += 1
for i in range(n):
	if a[i] == 'S':
		(l, r) = (0, 0)
		if i > 0 and a[i - 1] == 'G':
			for j in range(i - 1, -1, -1):
				if a[j] == 'G':
					r += 1
				else:
					break
		if i < n - 1 and a[i + 1] == 'G':
			for j in range(i + 1, n):
				if a[j] == 'G':
					l += 1
				else:
					break
		if l + r < c:
			ans = max(ans, l + r + 1)
		else:
			ans = max(ans, l + r)
if c == n:
	print(n)
else:
	print(ans)


x = int(input())
string = input()
last = 0
new = 0
maximum = 0
if string.count('G') == 0:
	print(0)
else:
	for i in string:
		if i == 'G':
			new += 1
		else:
			maximum = max(maximum, new + last)
			last = new
			new = 0
	if string.count('S') == 1:
		print(x - 1)
	elif string.count('S') == 0:
		print(x)
	elif maximum == 0:
		print(x - string.count('S'))
	else:
		maximum = max(maximum + 1, new + last + 1)
		if maximum >= string.count('G'):
			print(string.count('G'))
		else:
			print(maximum)


n = int(input())
s = input()
liste = s.split('S')
arr = [len(i) for i in liste]
ct = 0
for i in arr:
	if i > 0:
		ct += 1
two = ct == 2
more = ct > 1
ans = 0
if len(arr) == 1:
	print(arr[0])
else:
	for i in range(len(arr) - 1):
		if arr[i] == 0 or arr[i + 1] == 0 or two:
			ans = max(ans, arr[i] + arr[i + 1])
		else:
			ans = max(ans, arr[i] + arr[i + 1] + 1)
	if more:
		ans = max(ans, max(arr) + 1)
	print(ans)


n = int(input())
trophies = input()
left = []
right = []
totalGold = 0
for i in range(n):
	left.append(0)
	right.append(0)
	if trophies[i] == 'G':
		left[i] = 1
		totalGold += 1
		if i > 0:
			left[i] += left[i - 1]
for i in range(n - 1, -1, -1):
	if trophies[i] == 'G':
		right[i] = 1
		if i < n - 1:
			right[i] += right[i + 1]
if totalGold == n:
	print(totalGold)
elif totalGold == 0:
	print(0)
else:
	answer = 0
	for i in range(n):
		if trophies[i] == 'S':
			if i == 0:
				temp = right[i + 1]
			elif i == n - 1:
				temp = left[i - 1]
			else:
				temp = left[i - 1] + right[i + 1]
			if temp < totalGold:
				temp += 1
			answer = max(temp, answer)
	print(answer)


n = int(input())
s = input()
Gs = list(filter(lambda x: x, s.split('S')))
Ss = list(filter(lambda x: x, s.split('G')))
cG = s.count('G')
if cG == n:
	print(n)
	exit(0)
if cG == 0:
	print(0)
	exit(0)
if cG == 1:
	print(1)
	exit(0)
mi = len(max(Gs)) if cG - len(max(Gs)) == 0 else len(max(Gs)) + 1
cand = [mi]
for (i, e) in enumerate(Ss):
	if len(e) == 1:
		if s[0] == 'G':
			pre = 0 if i >= len(Gs) else len(Gs[i])
			pos = 0 if i + 1 >= len(Gs) else len(Gs[i + 1])
			if cG - (pre + pos) > 0:
				cand.append(pre + pos + 1)
			elif cG - (pre + pos) == 0:
				cand.append(pre + pos)
		else:
			pre = 0 if i - 1 < 0 else len(Gs[i - 1])
			pos = 0 if i >= len(Gs) else len(Gs[i])
			if cG - (pre + pos) > 0:
				cand.append(pre + pos + 1)
			elif cG - (pre + pos) == 0:
				cand.append(pre + pos)
print(max(cand))


n = int(input())
s = input()
lst = []
cnt = 0
for i in s:
	if i == 'G':
		cnt += 1
	elif cnt != 0:
		lst.append(cnt)
		cnt = 0
		lst.append(0)
	else:
		lst.append(0)
lst.append(cnt)
cnt2 = 0
for i in lst:
	if i > 0:
		cnt2 += 1
if cnt2 == 0:
	print(0)
elif cnt2 == 1:
	print(max(lst))
elif cnt2 == 2:
	ans = 0
	for i in range(len(lst) - 2):
		ans = max(lst[i] + lst[i + 2], ans)
	print(max(ans, max(lst) + 1))
else:
	ans = 0
	for i in range(len(lst) - 2):
		ans = max(lst[i] + lst[i + 2] + 1, ans)
	print(ans)


n = int(input())
c = input()
c = c + 'S'
total = []
i = 0
while i < n:
	q = True
	if c[i:i + 1] == 'G':
		curr = i
		miss = 0
		ans = 1
		back = n
		i += 1
		while miss < 2 and i < n:
			if c[i:i + 1] != 'G':
				miss += 1
				if q:
					back = i
					q = False
			else:
				ans += 1
			i += 1
		total.append([ans, curr, i])
		i = back
	else:
		i += 1
total.sort()
if total == []:
	print(0)
	exit()
for i in range(0, total[-1][1]):
	if c[i:i + 1] == 'G':
		print(total[-1][0] + 1)
		exit()
for i in range(total[-1][2], n):
	if c[i:i + 1] == 'G':
		print(total[-1][0] + 1)
		exit()
print(total[-1][0])


n = int(input())
gs = input()
bign = 100033
cnt = 0
gsum = 0
maxcnt = 0
precnt = [0 for i in range(bign)]
for i in range(len(gs)):
	if gs[i] == 'G':
		precnt[i] = precnt[i - 1] + 1
		gsum += 1
	else:
		precnt[i] = 0
	maxcnt = max(maxcnt, precnt[i] + 1)
nowcnt = 0
for i in range(len(gs)):
	if gs[n - 1 - i] == 'S':
		maxcnt = max(precnt[n - i - 1 - 1] + 1 + nowcnt, maxcnt)
		nowcnt = 0
	else:
		nowcnt += 1
print(min(maxcnt, gsum))


from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10000000)

class Operation:

	def __init__(self, name, function, function_on_equal, neutral_value=0):
		self.name = name
		self.f = function
		self.f_on_equal = function_on_equal

def add_multiple(x, count):
	return x * count

def min_multiple(x, count):
	return x

def max_multiple(x, count):
	return x
sum_operation = Operation('sum', sum, add_multiple, 0)
min_operation = Operation('min', min, min_multiple, 1000000000.0)
max_operation = Operation('max', max, max_multiple, -1000000000.0)

class SegmentTree:

	def __init__(self, array, operations=[sum_operation, min_operation, max_operation]):
		self.array = array
		if type(operations) != list:
			raise TypeError('operations must be a list')
		self.operations = {}
		for op in operations:
			self.operations[op.name] = op
		self.root = SegmentTreeNode(0, len(array) - 1, self)

	def query(self, start, end, operation_name):
		if self.operations.get(operation_name) == None:
			raise Exception('This operation is not available')
		return self.root._query(start, end, self.operations[operation_name])

	def summary(self):
		return self.root.values

	def update(self, position, value):
		self.root._update(position, value)

	def update_range(self, start, end, value):
		self.root._update_range(start, end, value)

	def __repr__(self):
		return self.root.__repr__()

class SegmentTreeNode:

	def __init__(self, start, end, segment_tree):
		self.range = (start, end)
		self.parent_tree = segment_tree
		self.range_value = None
		self.values = {}
		self.left = None
		self.right = None
		if start == end:
			self._sync()
			return
		self.left = SegmentTreeNode(start, start + (end - start) // 2, segment_tree)
		self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end, segment_tree)
		self._sync()

	def _query(self, start, end, operation):
		if end < self.range[0] or start > self.range[1]:
			return None
		if start <= self.range[0] and self.range[1] <= end:
			return self.values[operation.name]
		self._push()
		left_res = self.left._query(start, end, operation) if self.left else None
		right_res = self.right._query(start, end, operation) if self.right else None
		if left_res is None:
			return right_res
		if right_res is None:
			return left_res
		return operation.f([left_res, right_res])

	def _update(self, position, value):
		if position < self.range[0] or position > self.range[1]:
			return
		if position == self.range[0] and self.range[1] == position:
			self.parent_tree.array[position] = value
			self._sync()
			return
		self._push()
		self.left._update(position, value)
		self.right._update(position, value)
		self._sync()

	def _update_range(self, start, end, value):
		if end < self.range[0] or start > self.range[1]:
			return
		if start <= self.range[0] and self.range[1] <= end:
			self.range_value = value
			self._sync()
			return
		self._push()
		self.left._update_range(start, end, value)
		self.right._update_range(start, end, value)
		self._sync()

	def _sync(self):
		if self.range[0] == self.range[1]:
			for op in self.parent_tree.operations.values():
				current_value = self.parent_tree.array[self.range[0]]
				if self.range_value is not None:
					current_value = self.range_value
				self.values[op.name] = op.f([current_value])
		else:
			for op in self.parent_tree.operations.values():
				result = op.f([self.left.values[op.name], self.right.values[op.name]])
				if self.range_value is not None:
					bound_length = self.range[1] - self.range[0] + 1
					result = op.f_on_equal(self.range_value, bound_length)
				self.values[op.name] = result

	def _push(self):
		if self.range_value is None:
			return
		if self.left:
			self.left.range_value = self.range_value
			self.right.range_value = self.range_value
			self.left._sync()
			self.right._sync()
			self.range_value = None

	def __repr__(self):
		ans = '({}, {}): {}\n'.format(self.range[0], self.range[1], self.values)
		if self.left:
			ans += self.left.__repr__()
		if self.right:
			ans += self.right.__repr__()
		return ans

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def test_print(*args):
	if testingMode:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result
TestCases = False
testingMode = False
optimiseForReccursion = False

def main():
	n = get_int()
	li = list(input())
	g_count = li.count('G')
	s_count = li.count('S')
	if s_count == 0:
		print(g_count)
		return
	becky_g = 0
	res = 0
	for (i, ele) in enumerate(li):
		if ele == 'G':
			becky_g += 1
		else:
			k = i + 1
			forward_g = 0
			while k < n:
				if li[k] != 'G':
					break
				forward_g += 1
				k += 1
			ans = becky_g + forward_g
			if g_count > ans:
				ans += 1
			res = max(res, ans)
			becky_g = 0
	print(res)
if TestCases:
	for _ in range(get_int()):
		cProfile.run('main()') if testingMode else main()
else:
	(cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()


n = int(input())
s = input()
s = '0' + s + '0'
L = [0] * (n + 2)
if s[1] == 'G':
	L[1] = 1
for i in range(2, n + 1):
	L[i] = 0 if s[i] == 'S' else L[i - 1] + 1
R = [0] * (n + 2)
if s[n] == 'G':
	R[n] = 1
for i in range(n - 1, 0, -1):
	R[i] = 0 if s[i] == 'S' else R[i + 1] + 1
g = s.count('G')
m = 0
if g == n:
	m = n
else:
	for i in range(1, n + 1):
		if s[i] == 'S':
			if L[i - 1] + R[i + 1] < g:
				m = max(m, L[i - 1] + R[i + 1] + 1)
			else:
				m = max(m, L[i - 1] + R[i + 1])
print(m)


from sys import stdin
input = stdin.readline
n = int(input())
s = 'a' + input().rstrip()
l = [0] * (n + 1)
r = [0] * (n + 1)
cnt_g = 0
for i in range(len(s)):
	if s[i] == 'G':
		cnt_g += 1
if n == cnt_g:
	print(n)
	exit()
for i in range(1, n + 1):
	if s[i] == 'G':
		l[i] = r[i] = 1
for i in range(1, n + 1):
	if s[i] == 'G' and s[i - 1] == 'G':
		l[i] += l[i - 1]
for i in range(1, n + 1)[::-1]:
	if s[i] == 'G' and s[i - 1] == 'G':
		r[i - 1] += r[i]
ans = 0
for i in range(1, n):
	if l[i - 1] + r[i + 1] < cnt_g:
		ans = max(ans, l[i - 1] + r[i + 1] + 1)
	elif l[i - 1] + r[i + 1] == cnt_g:
		ans = max(ans, l[i - 1] + r[i + 1])
print(ans)


class Segment(object):

	def __init__(self, start_pos, size):
		self.start_pos = start_pos
		self.size = size

def solve(trophies):
	L = len(trophies)
	start_pos = 0
	golden_segments = []
	for i in range(1, L):
		if trophies[i] != trophies[i - 1] and trophies[i - 1] == 'G':
			s = Segment(start_pos, i - start_pos)
			golden_segments.append(s)
		if trophies[i] != trophies[i - 1]:
			start_pos = i
	if trophies[L - 1] == 'G':
		golden_segments.append(Segment(start_pos, L - start_pos))
	if len(golden_segments) == 0:
		return 0
	maxi = 0
	for i in range(0, len(golden_segments)):
		corr = 0
		if len(golden_segments) > 1:
			corr = 1
		maxi = max(maxi, golden_segments[i].size + corr)
		if i == 0:
			continue
		prev = golden_segments[i - 1]
		if golden_segments[i].start_pos == prev.start_pos + prev.size + 1:
			corr = 1
			if len(golden_segments) < 3:
				corr = 0
			maxi = max(maxi, golden_segments[i].size + prev.size + corr)
	return maxi

def main():
	n = int(input())
	trophies = input()
	res = solve(trophies)
	print(res)
main()


n = int(input())
s = input()
s = list(s)
cnt = 0
cnt2 = 0
A = []
cntg = 0
for i in range(n):
	if s[i] == 'G':
		cntg += 1
		cnt += 1
		if cnt2 == 0:
			continue
		A.append(cnt2)
		cnt2 = 0
	else:
		cnt2 += 1
		if cnt == 0:
			continue
		A.append(cnt)
		cnt = 0
if cnt:
	A.append(cnt)
elif cnt2:
	A.append(cnt2)
if s[0] == 'G':
	ans1 = 0
	for i in range(0, len(A), 2):
		ans1 = max(ans1, A[i])
	for i in range(1, len(A), 2):
		if A[i] == 1:
			if i >= 1 and i < len(A) - 1:
				if cntg > A[i - 1] + A[i + 1]:
					ans1 = max(ans1, A[i - 1] + A[i + 1] + 1)
				else:
					ans1 = max(ans1, A[i - 1] + A[i + 1])
		else:
			if cntg > A[i - 1]:
				ans1 = max(ans1, A[i - 1] + 1)
			if i <= len(A) - 2 and cntg > A[i + 1]:
				ans1 = max(ans1, A[i + 1] + 1)
	print(ans1)
else:
	ans2 = 0
	for i in range(1, len(A), 2):
		ans2 = max(ans2, A[i])
	for i in range(2, len(A) - 1, 2):
		if A[i] == 1:
			if i >= 1 and i <= len(A) - 2:
				if cntg > A[i - 1] + A[i + 1]:
					ans2 = max(ans2, A[i - 1] + A[i + 1] + 1)
				else:
					ans2 = max(ans2, A[i - 1] + A[i + 1])
		else:
			if cntg > A[i - 1]:
				ans2 = max(ans2, A[i - 1] + 1)
			if i <= len(A) - 2 and cntg > A[i + 1]:
				ans2 = max(ans2, A[i + 1] + 1)
	print(ans2)


n = int(input())
strings = input()
i = 1
G = strings.count('G')
longest = 0
array = [[strings[0], 1]]
while i < len(strings):
	if strings[i] in array[-1]:
		array[-1][1] += 1
	else:
		array.append([strings[i], 1])
	i += 1
for r in range(len(array)):
	if 'G' in array[r]:
		longest = max(longest, array[r][1] + 1)
	if array[r] == ['S', 1] and r != len(array) - 1 and (r != 0):
		longest = max(longest, array[r - 1][1] + array[r + 1][1] + 1)
print(min(longest, G))


n = int(input())
s = input()
f = s[0]
ans = []
ct = []
c = 0
for i in range(n):
	if s[i] == f:
		c += 1
	else:
		ans.append(f)
		ct.append(c)
		f = s[i]
		c = 1
ans.append(f)
ct.append(c)
l = len(ans)
fin = 0
for i in range(l):
	if ans[i] == 'S':
		if ct[i] == 1 and i - 1 >= 0 and (i + 1 < l):
			if i + 3 < l or i - 3 >= 0:
				fin = max(fin, ct[i - 1] + ct[i + 1] + 1)
			else:
				fin = max(fin, ct[i - 1] + ct[i + 1])
		elif i - 1 >= 0 and i + 1 < l:
			fin = max(fin, ct[i - 1] + 1, ct[i + 1] + 1)
	if ans[i] == 'G':
		fin = max(fin, ct[i])
print(fin)


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, file=sys.stderr)
	dprint('debug mode')
except Exception:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N,) = getIntList()
s = input()
z = []
for i in range(N):
	if i == 0:
		z.append([s[0], 1])
	elif s[i] == z[-1][0]:
		z[-1][1] += 1
	else:
		z.append([s[i], 1])
dprint(z)
tg = 0
re = 0
for x in z:
	if x[0] == 'G':
		tg += 1
		re = max(re, x[1])
if tg > 1:
	re += 1
for i in range(len(z) - 2):
	x = z[i]
	if x[0] == 'S':
		continue
	if z[i + 1][1] != 1:
		continue
	t = x[1] + z[i + 2][1]
	if tg > 2:
		t += 1
	re = max(re, t)
print(re)