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
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

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().strip())
s = input().strip().split('S')
length = 0
flag = False
cnt = 0
neighbor = False
for i in range(len(s)):
	if i == len(s) - 1:
		nsum = len(s[i])
	else:
		nsum = len(s[i]) + len(s[i + 1])
		if s[i] != '' and s[i + 1] != '' and (nsum > length):
			neighbor = True
	length = max(length, nsum)
	if s[i] != '':
		cnt += 1
if cnt > 2:
	neighbor = False
if cnt <= 1:
	neighbor = True
if cnt <= 2 and neighbor:
	print(length)
else:
	print(length + 1)


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)


input()
a = list(map(len, input().split('S')))
if sum((1 for s in a if s != 0)) == 1:
	print(max(a))
elif sum((1 for s in a if s != 0)) == 2:
	for i in range(len(a)):
		cur = a[i]
		if i < len(a) - 1 and a[i + 1] > 0 and a[i]:
			print(sum(a))
			exit(0)
	print(max(a) + 1)
else:
	ans = 0
	for i in range(len(a)):
		if i and a[i - 1] > 0:
			ans = max(a[i] + a[i - 1] + 1, ans)
		if i < len(a) - 1 and a[i + 1] > 0:
			ans = max(a[i] + a[i + 1] + 1, ans)
	print(max(max(a), 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)


from sys import exit
n = int(input())
s = input()
cntg = s.count('G')
if cntg == 0:
	print(0)
	exit(0)
a = [[s[0], 1]]
for (prev, cur) in zip(s[0:], s[1:]):
	if cur != prev:
		a.append([cur, 1])
	else:
		a[-1][1] += 1
ans = max((i[1] + (1 if i[1] < cntg else 0) for i in a if i[0] == 'G'))
for (prev, cur, nxt) in zip(a[0:], a[1:], a[2:]):
	if cur[0] == 'G':
		continue
	if cur[1] != 1:
		continue
	t = prev[1] + nxt[1]
	ans = max(ans, t + (1 if t < cntg else 0))
print(ans)


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)


from sys import stdin
n = int(stdin.readline().strip())
s = stdin.readline().strip()
acum = [0 for i in range(n)]
acum1 = [0 for i in range(n)]
if s[0] == 'G':
	acum[0] = 1
zer = 0
for i in range(1, n):
	if s[i] == 'G':
		acum[i] = acum[i - 1] + 1
if s[-1] == 'G':
	acum1[n - 1] = 1
for i in range(n - 2, -1, -1):
	if s[i] == 'G':
		acum1[i] = acum1[i + 1] + 1
for i in range(1, n):
	if acum[i] == 0 and acum[i - 1] != 0:
		zer += 1
if s[-1] == 'G':
	zer += 1
mx = max(acum)
if zer <= 1:
	print(mx)
	exit(0)
ans = mx + 1
for i in range(1, n - 1):
	if acum[i] == 0 and acum[i - 1] != 0 and (acum1[i + 1] != 0):
		aux = 0
		if zer > 2:
			aux = 1
		ans = max(ans, acum[i - 1] + acum1[i + 1] + aux)
print(ans)


n = int(input())
string = 'S' + input() + 'SS'
groups = [x for x in string.split('S') if len(x) > 0]
lst = list()
for idx in range(len(string)):
	if string[idx] == 'S':
		lst.append(idx)
ans = 0
for idx in range(1, len(lst) - 1):
	mx = lst[idx + 1] - lst[idx - 1] - 2
	if len(groups) > 2:
		mx += 1
	elif len(groups) > 1 and lst[idx + 1] - lst[idx] == 1 and (lst[idx] - lst[idx - 1] != 1):
		mx += 1
	elif len(groups) > 1 and lst[idx + 1] - lst[idx] != 1 and (lst[idx] - lst[idx - 1] == 1):
		mx += 1
	ans = max(ans, mx)
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))


import math
n = int(input())
s = input()
l = [0]
ll = [0] * n
rr = [0] * n
prev = 'G'
for i in range(n):
	if s[i] == prev:
		l[-1] += 1
	else:
		prev = s[i]
		l.append(1)
cc = 0
for i in range(len(l)):
	if i & 1:
		for j in range(cc, cc + l[i]):
			ll[j] = 0
	else:
		for j in range(cc, cc + l[i]):
			ll[j] = l[i] + (cc - j)
	cc = cc + l[i]
cc = 0
for i in range(len(l)):
	if i & 1:
		for j in range(cc, cc + l[i]):
			rr[j] = 0
	else:
		for j in range(cc, cc + l[i]):
			rr[j] = j - cc + 1
	cc = cc + l[i]
h = s.count('G')
ans = 0
for i in range(n):
	if s[i] == 'S':
		if i > 0 and i < n - 1:
			if rr[i - 1] + ll[i + 1] < h:
				ans = max(ans, rr[i - 1] + ll[i + 1] + 1)
			else:
				ans = max(ans, rr[i - 1] + ll[i + 1])
		elif i > 0:
			ans = max(ans, rr[i - 1])
		elif i < n - 1:
			ans = max(ans, ll[i + 1])
if h == n:
	ans = n
print(ans)


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)


import os
import sys
from io import BytesIO, IOBase

def get(x):
	return x[1] - x[0] + 1

def main():
	n = int(input())
	s = input().rstrip()
	(a, i) = ([], 0)
	while i < n:
		if s[i] == 'G':
			j = i
			while j < n and s[j] == 'G':
				j += 1
			a.append((i, j - 1))
			i = j
		i += 1
	z = s.count('G')
	ma = 0
	if a:
		ma = get(max(a, key=lambda x: get(x)))
		a.sort()
		for i in range(len(a) - 1):
			if a[i + 1][0] - a[i][1] - 1 == 1:
				x = get(a[i]) + get(a[i + 1])
				ma = max(ma, x + (z > x))
			else:
				x = get(a[i])
				ma = max(ma, x + (z > x))
		x = get(a[-1])
		ma = max(ma, x + (z > x))
	print(ma)
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')
main()


(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))


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


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)


n = int(input())
s = input()
d = {}
i = 0
ans = 0
while i < n:
	if s[i] == 'G':
		cnt = 1
		j = i + 1
		while j < n:
			if s[j] == 'G':
				cnt += 1
				j += 1
			else:
				break
		ans = max(ans, cnt)
		d[i] = (cnt, j - 1)
		i = j
	else:
		i += 1
k = list(d.keys())
for i in range(len(k) - 1):
	cnt1 = d[k[i]][0]
	cnt2 = d[k[i + 1]][0]
	end = d[k[i]][1]
	start = k[i + 1]
	if abs(end - start) == 2:
		if len(d) > 2:
			ans = max(ans, cnt1 + cnt2 + 1)
		else:
			ans = max(ans, cnt1 + cnt2)
	else:
		ans = max(ans, max(cnt1 + 1, cnt2 + 1))
print(ans)


import sys
import unittest
from math import ceil as up
MAX_TROPHIES = 100000

def B1082(colors):
	curr = 0
	prev = 0
	is_swapped = False
	first_G = False
	swap_count = 0
	prev_trophy = 'G'
	tG = colors.count('G')
	tS = colors.count('S')
	if tG == 0:
		return 0
	if tS == 0:
		return tG
	for c in colors:
		if c == 'S' and (not first_G):
			continue
		if curr == tG:
			break
		if c == 'G':
			curr += 1
			first_G = True
		elif c == 'S' and (not is_swapped):
			swap_count = curr
			if curr == tG:
				break
			curr += 1
			is_swapped = True
		else:
			prev = max(curr, prev)
			if prev_trophy == 'S':
				swap_count = 0
				curr = 1
			else:
				swap_count = curr - swap_count - 1
				curr = 1 + swap_count
		prev_trophy = c
	return max(curr, prev)

def B1082_wrapper(colors):
	print('{}'.format(B1082(colors)))

def sanity_check(trophies, colors):
	if trophies < 2 or trophies > MAX_TROPHIES:
		print('[error] Number of trophies entered is invalid.')
		exit(-1)
	if colors.count('G') + colors.count('S') != trophies:
		print('[error] Number of entered G and S are different than trophies.')
		exit(-1)

def B1082_stdio():
	trophies = int(sys.stdin.readline(), 10)
	colors = sys.stdin.readline()
	sanity_check(trophies, colors)
	B1082_wrapper(colors)

def B1082_file(filename):
	f = open(filename, 'r')
	b_1082 = f.readlines()
	try:
		trophies = int(b_1082[0], 10)
		sanity_check(trophies, b_1082[1])
	except ValueError:
		print('[error] Entered value is not an integer {}.'.format(given_tests[0]))
		exit(0)
	B1082_wrapper(b_1082[1])
B1082_stdio()


n = int(input())
s = input()
a = [0] * 100005
(ans, maxn) = (0, 0)
for i in range(0, n):
	if s[i] == 'G':
		if i == 0:
			a[0] = 1
		else:
			a[i] = a[i - 1] + 1
		maxn = max(maxn, a[i])
		ans += 1
for i in range(n - 2, -1, -1):
	if s[i] == 'G':
		a[i] = max(a[i], a[i + 1])
for i in range(0, n):
	if i > 0 and i < n - 1 and (s[i] == 'S') and (s[i - 1] == 'G') and (s[i + 1] == 'G') and (a[i - 1] + a[i + 1] != ans):
		maxn = max(maxn, a[i - 1] + a[i + 1] + 1)
		continue
	if i > 0 and i < n - 1 and (s[i] == 'S') and (s[i - 1] == 'G') and (s[i + 1] == 'G'):
		maxn = max(maxn, a[i - 1] + a[i + 1])
		continue
	if s[i] == 'G' and a[i] != ans:
		maxn = max(maxn, a[i] + 1)
print(maxn)


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)


import collections
k = int(input())
line = input()
n = line.split('S')
d = collections.Counter(line)
if len(n) == 1:
	print(len(n[0]))
else:
	m = 0
	for i in range(1, len(n)):
		if len(n[i - 1]) + len(n[i]) < d['G']:
			m = max(m, len(n[i - 1]) + len(n[i]) + 1)
		else:
			m = max(m, len(n[i - 1]) + len(n[i]))
	print(m)


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')))


import sys
n = int(sys.stdin.readline())
s = str(sys.stdin.readline())[:-1].split('S')
single = False
mx = len(s[0])
blocks = 0
canConc = False
if mx > 0:
	blocks += 1
for i in range(1, len(s)):
	tmpSum = len(s[i - 1]) + len(s[i])
	if len(s[i]) > 0:
		blocks += 1
		if len(s[i - 1]) > 0:
			canConc = True
	if tmpSum > mx:
		mx = tmpSum
if blocks > 2 and canConc:
	mx += 1
elif canConc == False:
	if blocks >= 2:
		mx += 1
print(mx)


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)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in range(base ** n):
		s = [tb // base ** bt % base for bt in range(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.size = len(ls) + 1
				(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in edge]) for edge in self.edges]):
			print([[nd for (nd, d) in edge] for edge in self.edges])
		else:
			print(self)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0

def bfs(edge, st):
	n = len(edge)
	q = deque([st])
	v = [-1] * n
	v[st] = 0
	while q:
		cur = q.popleft()
		for (nx, _) in edge[cur]:
			if v[nx] == -1:
				v[nx] = v[cur] + 1
				q.append(nx)
	return v
show_flg = False
show_flg = True
ans = 0
n = I()
s = input() + 'S'
lst = None
gs = []
l = 0
last = None
for i in range(n + 1):
	c = s[i]
	if c == 'G':
		l += 1
		e = i
		last = (e, l)
	else:
		if last != None:
			(e, l) = last
			gs += [(e - l, e)]
			last = None
		l = 0
ans = 0
x = (len(gs) > 2) * 1
if gs:
	ans = gs[0][1] - gs[0][0] + (len(gs) > 1) * 1
for i in range(len(gs) - 1):
	(a, b) = gs[i]
	(c, d) = gs[i + 1]
	ans = max(ans, b - a + 1, d - c + 1)
	if b + 1 == c:
		ans = max(ans, b - a + d - c + x)
print(ans)


import sys
n = int(input())
s = str(input())
pre = cnt = ans = now = 0
gcnt = 0
for i in range(n):
	if s[i] == 'G':
		now += 1
		gcnt += 1
		cnt = 0
	else:
		cnt += 1
		if pre + now > ans:
			ans = pre + now
		pre = now
		now = 0
		if cnt > 1:
			pre = 0
ans = max(ans, pre + now)
if gcnt > ans:
	ans += 1
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())
string = 'S' + input() + 'S'
arr = []
c = 0
prev = 0
for i in string:
	if i == 'S':
		if c > 0:
			arr += [(c + prev, prev > 0)]
		prev = c
		c = 0
	else:
		c += 1
if len(arr) == 0:
	print(0)
	exit()
maxm = max(arr, key=lambda i: i[0])
print(maxm[0] + (len(arr) > 1 + maxm[1]))


n = int(input())
s = input()
l = []
d = []
gcnt = scnt = 0
g = False
if s[0] == 'G':
	g = True
	gcnt = 1
else:
	g = False
	scnt = 1
a = s[1:]
for i in a:
	if i == 'G':
		if g:
			gcnt += 1
		else:
			d.append(scnt)
			scnt = 0
			gcnt = 1
			g = True
	elif not g:
		scnt += 1
	else:
		l.append(gcnt)
		gcnt = 0
		scnt = 1
		g = False
if gcnt:
	l.append(gcnt)
else:
	d.append(scnt)
st = 0
if s[0] == 'S':
	st = d[0]
	d.pop(0)
res = 0
sz = len(l)
dsz = len(d)
if l:
	res = max(l)
for i in range(sz):
	if i == 0:
		if sz >= 2 and (st or d):
			res = max(res, l[i] + 1)
	elif sz >= 2 and d:
		res = max(res, l[i] + 1)
	if i == sz - 1:
		break
	if d[i] == 1 and sz >= 3:
		res = max(res, l[i] + l[i + 1] + 1)
	if d[i] == 1:
		res = max(res, l[i] + l[i + 1])
print(res)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	n = int(input())
	s = input()
	(g, sl) = (0, 0)
	for i in s:
		if i == 'G':
			g += 1
		else:
			sl += 1
	if g == 1 or g == 0:
		print(g)
	elif sl == 0:
		print(g)
	elif sl == 1:
		(t1, t2) = (0, 0)
		ok = False
		for i in s:
			if i == 'S':
				ok = True
				continue
			if not ok:
				t1 += 1
			else:
				t2 += 1
		print(t1 + t2)
	else:
		pre = [0] * (n + 1)
		suf = [0] * (n + 2)
		for i in range(n):
			if s[i] == 'G':
				pre[i + 1] = pre[i] + 1
			else:
				pre[i + 1] = 0
		for i in range(n - 1, -1, -1):
			if s[i] == 'G':
				suf[i + 1] = suf[i + 2] + 1
			else:
				suf[i + 1] = 0
		ans = -1
		for i in range(1, n + 1):
			if pre[i] == 0:
				v = g - (pre[i - 1] + suf[i + 1])
				if v > 1:
					v = 1
				ans = max(ans, pre[i - 1] + suf[i + 1] + v)
		print(ans)
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')
main()


n = int(input())
s = input()
s = s.split('S')
d = 0
for i in range(len(s) - 1):
	flag = 0
	for j in range(len(s)):
		if j != i and j != i + 1 and (len(s[j]) != 0):
			flag = 1
			break
	t = 0
	if flag == 1:
		t = len(s[i]) + len(s[i + 1]) + 1
	else:
		t = len(s[i]) + len(s[i + 1])
	if t > d:
		d = t
if len(s) == 1:
	d = len(s[0])
print(d)


n = int(input())
A = input()
x = A.count('G')
num_1 = 0
num_2 = 0
max_num = 0
flag = 0
for i in range(n):
	if A[i] == 'G' and flag == 0:
		num_1 += 1
	elif A[i] == 'G' and flag == 1:
		num_2 += 1
	elif A[i] == 'S' and flag == 0:
		flag = 1
	elif num_1 + num_2 + 1 <= x:
		if num_1 + num_2 + 1 > max_num:
			max_num = num_1 + num_2 + 1
		num_1 = num_2
		num_2 = 0
		flag = 1
	else:
		if num_2 + num_1 > max_num:
			max_num = num_1 + num_2
		num_1 = num_2
		num_2 = 0
		flag = 1
if num_1 + num_2 + 1 <= x:
	if num_1 + num_2 + 1 > max_num:
		max_num = num_1 + num_2 + 1
elif num_2 + num_1 > max_num:
	max_num = num_1 + num_2
print(max_num)


n = int(input())
s = input()
max = 0
l = 0
has_s = False
gs = 0
for r in range(n):
	if s[r] == 'G':
		gs += 1
	elif not has_s:
		has_s = True
	else:
		while s[l] == 'G':
			l += 1
		l += 1
	if r - l + 1 > max:
		max = r - l + 1
ans = max
if gs < max:
	ans -= 1
print(ans)


n = int(input())
s = input()
arr = []
cnt = 0
for i in range(n):
	if s[i] == 'G':
		cnt += 1
	else:
		if cnt:
			arr.append(cnt)
		cnt = 0
if cnt:
	arr.append(cnt)
i = 0
while i < n and s[i] == 'S':
	i += 1
arr1 = []
cnt = 0
while i < n:
	if s[i] == 'S':
		cnt += 1
	else:
		if cnt:
			arr1.append(cnt)
		cnt = 0
	i += 1
if len(arr1) == 0:
	if arr:
		print(arr[0])
	else:
		print(0)
elif len(arr1) == 1:
	if arr1[0] == 1:
		print(sum(arr))
	else:
		print(max(arr) + 1)
else:
	mx = temp = max(arr) + 1
	for i in range(len(arr1)):
		if arr1[i] == 1:
			mx = max(mx, arr[i + 1] + arr[i] + 1)
	print(mx)


n = int(input())
cups = input()

def maxlength(cups):
	length = 0
	for i in cups:
		if i == 'G':
			length = length + 1
	return length
ll = cups.split('S')
themax = maxlength(cups)
maxl = 0
length = 0
for i in range(len(ll)):
	if len(ll[i]) > 0 and length > 0:
		length = len(ll[i]) + length
		if length > maxl:
			maxl = length
		length = len(ll[i])
	if length == 0 or len(ll[i]) == 0:
		length = len(ll[i])
	if length > maxl and length <= themax:
		maxl = length
if maxl < themax:
	maxl = maxl + 1
print(maxl)


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


import os
import sys
from io import BytesIO, IOBase
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')
import sys
n = int(input())
s = input()
if 'G' not in s:
	print(0)
	sys.exit()
p = [0] * n
if s[0] == 'G':
	p[0] = 1
s1 = [0] * n
if s[n - 1] == 'G':
	s1[n - 1] = 1
for i in range(1, n):
	if s[i] == 'G':
		p[i] = p[i - 1] + 1
	else:
		p[i] = 0
for i in range(n - 2, -1, -1):
	if s[i] == 'G':
		s1[i] = s1[i + 1] + 1
	else:
		s1[i] = 0
ind = s.index('G')
ind1 = n - 1 - s[::-1].index('G')
f = 0
for i in range(n):
	if i == 0:
		if s[0] == 'G':
			ans = s1[i + 1] + 1
		elif ind1 > i + s1[i + 1]:
			ans = s1[i + 1] + 1
		else:
			ans = s1[i + 1]
	elif i == n - 1:
		if s[i] == 'G':
			ans = p[i - 1] + 1
		elif ind < i - p[i - 1]:
			ans = p[i - 1] + 1
		else:
			ans = p[i - 1]
	elif s[i] == 'G':
		ans = p[i - 1] + s1[i + 1] + 1
	elif ind < i - p[i - 1] or ind1 > i + s1[i + 1]:
		ans = p[i - 1] + s1[i + 1] + 1
	else:
		ans = p[i - 1] + s1[i + 1]
	f = max(f, ans)
print(f)


def find_gold_runs(string):
	runs = []
	current_run = None
	for (i, c) in enumerate(string):
		if c == 'G':
			if current_run is None:
				current_run = (i, i + 1)
			else:
				current_run = (current_run[0], i + 1)
		elif c == 'S':
			if current_run is not None:
				runs.append(current_run)
				current_run = None
	if current_run is not None:
		runs.append(current_run)
	return runs

def longest_adjacent(runs):
	longest = float('-inf')
	longest_start = None
	for i in range(1, len(runs)):
		if runs[i][0] == runs[i - 1][1] + 1:
			length = runs[i][1] - runs[i - 1][0]
			if length > longest:
				longest = length
				longest_start = i - 1
	return (longest_start, longest)

def solve(string):
	runs = find_gold_runs(string)
	if len(runs) == 0:
		return 0
	elif len(runs) == 1:
		return runs[0][1] - runs[0][0]
	else:
		candidates = []
		(_, longest_adjacent_cand) = longest_adjacent(runs)
		if len(runs) > 2:
			candidates.append(longest_adjacent_cand)
		else:
			candidates.append(longest_adjacent_cand - 1)
		longest_individual = float('-inf')
		for run in runs:
			longest_individual = max(longest_individual, run[1] - run[0])
		candidates.append(longest_individual + 1)
		return max(candidates)
n = int(input())
string = input()[:n]
print(solve(string))


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))


import sys

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

def main():
	n = int(input())
	a = input().strip()
	g = a.count('G')
	if g == 0:
		print(0)
		return
	d = []
	now = 0
	for i in range(n):
		if a[i] == 'G':
			now += 1
		else:
			d.append(now)
			now = 0
	if a[n - 1] == 'G':
		d.append(now)
	ans = max(d)
	if ans != g:
		ans += 1
	for i in range(len(d) - 1):
		if d[i] + d[i + 1] < g:
			ans = max(ans, d[i] + d[i + 1] + 1)
		else:
			ans = max(ans, d[i] + d[i + 1])
	print(ans)
koala = 0
if koala:
	file = open('input.txt', 'r')
	input = file.readline
else:
	input = sys.stdin.readline
main()
if koala:
	file.close()


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 = int(input())
s = input()
l = [0] * n
r = [0] * n
for i in range(n):
	if s[i] == 'G':
		l[i] = 1
		if i > 0:
			l[i] += l[i - 1]
for i in range(n - 1, -1, -1):
	if s[i] == 'G':
		r[i] = 1
		if i + 1 < n:
			r[i] += r[i + 1]
cng = 0
for i in s:
	if i == 'G':
		cng += 1
mm = 0
for i in range(n):
	if s[i] == 'G':
		continue
	xx = 1
	if i - 1 > 0:
		xx += l[i - 1]
	if i + 1 < n:
		xx += r[i + 1]
	mm = max(mm, xx)
mm = min(cng, mm)
if cng == n:
	mm = n
print(mm)


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())
s = input()
golden_sub = s.split('S')
nG = 0
for c in s:
	if c == 'G':
		nG += 1
t = len(golden_sub)
if t == 1:
	print(len(golden_sub[0]))
else:
	ans = 0
	for i in range(t - 1):
		l1 = len(golden_sub[i])
		l2 = len(golden_sub[i + 1])
		if l1 + l2 < nG:
			ans = max(ans, l1 + l2 + 1)
		else:
			ans = max(ans, l1 + l2)
	print(ans)


n = int(input())
trophies = input()
arr = []
(i, j) = (0, 0)
while j < n:
	if trophies[j] == 'S':
		if i != j:
			arr.append((i, j))
		j += 1
		i = j
	else:
		j += 1
if i != j:
	arr.append((i, j))
mx = 0
if len(arr) != 0:
	mx = arr[0][1] - arr[0][0]
	for i in range(len(arr) - 1):
		(a, b) = arr[i]
		(c, d) = arr[i + 1]
		if c - b == 1 and len(arr) == 2:
			mx = max(mx, d - a - 1)
		elif c - b == 1 and len(arr) > 2:
			mx = max(mx, d - a)
		else:
			mx = max(mx, b - a + 1, d - c + 1)
print(mx)


n = int(input())
a = input()
b = []
c = 0
for i in range(1, n):
	if a[i] != a[i - 1]:
		b.append(i - c)
		c = i
b.append(n - c)
g = a.count('G')
if g == 0:
	print(0)
else:
	c = int(a[0] == 'S')
	d = b[c] + int(g != n and b[c] != g)
	for i in range(c, len(b) - 2, 2):
		d = max(d, b[i] + int(g != n and b[i] != g))
		if b[i] != g and b[i + 1] == 1 and (b[i] + b[i + 2] + int(b[i] + b[i + 2] < g) > d):
			d = b[i] + b[i + 2] + int(b[i] + b[i + 2] < g)
	if i + 2 < len(b):
		d = max(d, b[i + 2] + int(g != n and b[i + 2] != g))
	print(d)


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())
v = list(input())
s = []
a = b = -1
for i in range(n):
	if v[i] == 'G':
		if a == -1:
			a = i
		b = i
	else:
		if a != -1 and b != -1:
			s.append((a, b))
		a = b = -1
if a != -1 and b != -1:
	s.append((a, b))
o = 0
for i in range(len(s)):
	x = s[i]
	o = max(x[1] - x[0] + 1, o)
	if len(s) > 1:
		o = max(x[1] - x[0] + 2, o)
	if i < len(s) - 1:
		if s[i + 1][0] - x[1] == 2:
			u = x[1] - x[0] + 1 + s[i + 1][1] - s[i + 1][0] + 1
			if len(s) > 2:
				u += 1
			o = max(u, o)
print(o)


from __future__ import print_function
from itertools import permutations as perm
from functools import cmp_to_key
from fractions import Fraction
from collections import *
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
f = []
tg = 0
maxSubSeg = 0
ans = 0
for ch in g():
	if len(f) == 0 and ch == 'S':
		continue
	if ch == 'G':
		tg += 1
		if len(f) & 1:
			f[-1] += 1
		else:
			f.append(1)
		maxSubSeg = max(maxSubSeg, f[-1])
	elif len(f) & 1:
		f.append(1)
	else:
		f[-1] += 1
if maxSubSeg != tg:
	maxSubSeg += 1
f.append(0)
for i in range(1, len(f), 2):
	if f[i] != 1:
		continue
	s = f[i - 1] + f[i + 1]
	if s != tg:
		s += 1
	maxSubSeg = max(s, maxSubSeg)
print(maxSubSeg)


a = [0] * 100005
n = int(input())
string = input()
for i in range(1, n + 1):
	a[i] = a[i - 1] + (string[i - 1] == 'G')
l = 0
r = n + 1
ans = 0
while l < r:
	mid = int((l + r) / 2)
	ok = False
	for i in range(1, n + 1):
		if i + mid - 1 > n:
			break
		if a[i + mid - 1] - a[i - 1] >= mid - 1 and mid <= a[n]:
			ok = True
			break
	if ok:
		ans = mid
		l = mid + 1
	else:
		r = mid
print(ans)


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


def reverse_sweep(i, trophies):
	m = i - 1
	count = 0
	while m >= 0:
		if trophies[m] == 'S':
			break
		else:
			count += 1
		m -= 1
	return count

def forward_sweep(i, trophies, n):
	p = i + 1
	count = 0
	index = 0
	while p <= n - 1:
		if trophies[p] == 'S':
			break
		else:
			count += 1
			index += 1
		p += 1
	return count

def main():
	n = int(input())
	trophies = input()
	i = 1
	box = []
	Gcount = trophies.count('G')
	if Gcount == len(trophies) or Gcount == len(trophies) - 1:
		print(Gcount)
	elif Gcount == 0:
		print(0)
	elif Gcount == len(trophies) - 2 and trophies[0] == 'S' == trophies[-1]:
		print(Gcount)
	else:
		while i <= n - 2:
			if trophies[i] == 'S' and trophies[i + 1] == 'G' == trophies[i - 1]:
				box.append(forward_sweep(i, trophies, n) + reverse_sweep(i, trophies))
			elif trophies[i] == 'S' and trophies[i + 1] == 'G' and (trophies[i - 1] == 'S'):
				box.append(forward_sweep(i, trophies, n))
			elif trophies[i] == 'S' and trophies[i - 1] == 'G' and (trophies[i + 1] == 'S'):
				box.append(reverse_sweep(i, trophies))
			i += forward_sweep(i, trophies, n) + 1
		if Gcount > max(box):
			print(max(box) + 1)
		elif Gcount == max(box):
			print(Gcount)
main()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

def ria():
	return list(map(int, sys.stdin.readline().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')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		n = ri()
		s = rs()
		s = 'S' + s + 'S'
		ans = 0
		ng = 0
		for i in s:
			if i == 'G':
				ng += 1
		mg = 0
		t = 0
		for i in range(n + 2):
			if s[i] == 'G':
				t += 1
			else:
				mg = max(mg, t)
				t = 0
			if i - 1 >= 0 and i + 1 < len(s) and (s[i] == 'S') and (s[i - 1] == 'G') and (s[i + 1] == 'G'):
				p = i - 1
				a = i + 1
				c = 0
				while s[p] == 'G':
					p -= 1
					c += 1
				while s[a] == 'G':
					a += 1
					c += 1
				if c < ng:
					c += 1
				ans = max(ans, c)
		if mg < ng:
			mg += 1
		print(max(mg, ans))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


n = int(input())
s = input()
(prev_cnt, nxt_cnt, max_cnt) = (0, 0, 0)
for i in range(n):
	if s[i] == 'G':
		nxt_cnt += 1
	elif s[i] == 'S':
		if i != n - 1 and s[i + 1] == 'G':
			prev_cnt = nxt_cnt + 1
			nxt_cnt = 0
		elif i != n - 1 and s[i + 1] == 'S':
			max_cnt = max(max_cnt, nxt_cnt + 1)
			prev_cnt = 0
			nxt_cnt = 0
	max_cnt = max(max_cnt, prev_cnt + nxt_cnt)
if max_cnt > s.count('G'):
	print(max_cnt - 1)
else:
	print(max_cnt)


n = int(input())
s = input()
ans = 0
br1 = br2 = br = 0
for i in range(n):
	if s[i] == 'G':
		br2 = br2 + 1
		br = br + 1
	if s[i] == 'S':
		br1 = br2
		br2 = 0
	ans = max(ans, br1 + br2)
if ans == br:
	print(ans)
else:
	print(ans + 1)


import math
import os
import random
import re
import sys
n = int(input())
string = str(input())
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
	if string[i] == 'G':
		left[i] = 1
		if i > 0:
			left[i] += left[i - 1]
for i in range(n - 1, -1, -1):
	if string[i] == 'G':
		right[i] = 1
		if i < n - 1:
			right[i] += right[i + 1]
total = 0
ans = 0
for char in string:
	if char == 'G':
		total += 1
for i in range(n):
	if string[i] == 'G':
		continue
	newans = 1
	if i > 0:
		newans += left[i - 1]
	if i < n - 1:
		newans += right[i + 1]
	ans = max(newans, ans)
ans = min(ans, total)
if n == total:
	ans = total
print(ans)


input()
str = input()

def before(ind):
	if ind < 2:
		return 0
	if str[ind - 0] == 'G':
		return 1
	return 0

def after(ind):
	if ind + 2 >= len(str):
		return 0
	if str[ind + 2] == 'G':
		return 1
	return 0
answers = []
l_p = 0
while True:
	cur_ans = 0
	while l_p < len(str) and str[l_p] != 'G':
		l_p += 1
	if l_p == len(str):
		break
	r_p = l_p
	while str[r_p] == 'G':
		cur_ans += 1
		r_p += 1
		if r_p == len(str) or str[r_p] == 'S':
			answers.append((cur_ans, l_p, r_p - 1))
			if r_p == len(str):
				break
	l_p = r_p
ans = 0
if len(answers) == 1:
	print(answers[0][0])
elif len(answers) == 2:
	ans = max(answers[0][0], answers[1][0]) + 1
	if answers[0][2] + 2 == answers[1][1]:
		ans = answers[0][0] + answers[1][0]
	print(ans)
else:
	ans = 0
	for i in range(len(answers)):
		cur_ans = answers[i][0] + 1
		if i != 0 and answers[i - 1][2] + 2 == answers[i][1]:
			cur_ans = max(cur_ans, answers[i][0] + answers[i - 1][0] + 1)
		if i != len(answers) - 1 and answers[i][2] + 2 == answers[i + 1][1]:
			cur_ans = max(cur_ans, answers[i][0] + answers[i + 1][0] + 1)
		ans = max(ans, cur_ans)
	print(ans)


class Group:

	def __init__(self, m, c):
		self.m = m
		self.c = c

def parse_input():
	n = int(input())
	str = 'SS' + input().strip() + 'SS'
	g = Group('S', 0)
	for m in str:
		if m == g.m:
			g.c += 1
			continue
		yield g
		g = Group(m, 1)
	yield g
groups = list(parse_input())
glen = len(groups)
if glen == 1:
	print(0)
elif glen == 3:
	print(groups[1].c)
elif glen == 5:
	(c1, c2) = (groups[1].c, groups[3].c)
	if groups[2].c == 1:
		print(c1 + c2)
	else:
		print(1 + max(c1, c2))
else:
	ans = 1 + max(tuple((g.c for g in groups[1::2])))
	for (i, g) in enumerate(groups):
		if g.m != 'S' or g.c != 1:
			continue
		tmp = 1 + groups[i - 1].c + groups[i + 1].c
		ans = max(ans, tmp)
	print(ans)


def solve(lst):
	pre = [0] * len(lst)
	post = [0] * len(lst)
	count = 0
	for i in range(len(lst)):
		pre[i] = count
		if lst[i] == 'G':
			count += 1
		else:
			count = 0
	count = 0
	for i in reversed(range(len(lst))):
		post[i] = count
		if lst[i] == 'G':
			count += 1
		else:
			count = 0
	res = 0
	count = 0
	for i in range(len(lst)):
		res = max(pre[i] + post[i] + 1, res)
		if lst[i] == 'G':
			count += 1
	return min(res, count)
n = input()
lst = input()
print(solve(lst))


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)


n = int(input())
s = input()
l = [0] * n
r = [0] * n
for i in range(n):
	if s[i] == 'G':
		l[i] = 1
		if i > 0:
			l[i] += l[i - 1]
for i in range(n - 1, -1, -1):
	if s[i] == 'G':
		r[i] = 1
		if i + 1 < n:
			r[i] += r[i + 1]
c = 0
for i in s:
	if i == 'G':
		c += 1
m = 0
for i in range(n):
	if s[i] != 'G':
		x = 1
		if i - 1 > 0:
			x += l[i - 1]
		if i + 1 < n:
			x += r[i + 1]
		m = max(m, x)
m = min(c, m)
if c == n:
	m = n
print(m)


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))


def inint():
	return int(input())

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

def main():
	n = inint()
	a = input()
	a1 = [0 for i in range(n + 2)]
	a2 = a1[:]
	a3 = a1[:]
	ch = a.count('G')
	for i in range(1, n + 1):
		a1[i] = 1 if a[i - 1] == 'G' else 0
	for i in range(1, n + 1):
		a2[i] = a2[i - 1] + 1
		if a1[i] == 0:
			a2[i] = 0
	for i in range(n, 0, -1):
		a3[i] = a3[i + 1] + 1
		if a1[i] == 0:
			a3[i] = 0
	ans = 0
	for i in range(1, n + 1):
		ans = max(a2[i] + 1, ans)
		ans = max(a2[i - 1] + a3[i + 1] + 1, ans)
	if ans > ch:
		ans -= 1
	print(ans)
main()


n = int(input())
a = input()
p = [[0, 0]]
pi = -1
per_l = 2
c = 0
c1 = 0
if a.count('S') <= 1:
	print(len(a) - a.count('S'))
elif a.count('G') == 0:
	print(0)
else:
	for i in range(len(a)):
		if a[i] == 'G' and per_l >= 2:
			c += 1
			pi += 1
			p[pi][0] = 1
			per_l = 0
			p.append([1, 0])
		elif a[i] == 'G' and per_l == 1:
			c1 += 1
			pi += 1
			p[pi][1] = 1
			p[pi][0] += 1
			p.append([1, 1])
			per_l = 0
		elif a[i] == 'G' and per_l == 0:
			p[pi][0] += 1
			p[pi + 1][0] += 1
		else:
			per_l += 1
	max_l = max(p)
	if c + c1 == 1 or (c == 1 and c1 == 1):
		print(max_l[0])
	else:
		print(max_l[0] + 1)


n = int(input())
s = input()
if s.count('S') == 0:
	print(n)
	exit()
stack1 = []
stack2 = []
i = n - 1
while i > -1:
	if s[i] == 'G':
		stack2.append(i)
	i -= 1
stack2 = stack2[::-1]
l = {}
r = {}
prev = -1
flag = 0
for i in range(n):
	if s[i] == 'G':
		if flag:
			continue
		else:
			prev = i
			flag = 1
	elif flag:
		flag = 0
		l[i - 1] = prev
		r[prev] = i - 1
	else:
		continue
if flag:
	l[i] = prev
	r[prev] = i
	flag = 0
ans = 0
for i in range(n):
	if s[i] == 'G':
		if len(stack1) == 0:
			stack1.append(i)
	else:
		if i - 1 in l and i + 1 in r:
			fd = stack1[0]
			sd = stack2[-1]
			if fd == l[i - 1]:
				ans1 = 1 + (i - 1 - fd) + (r[i + 1] - (i + 1) + 1)
			else:
				ans1 = 1 + (i - 1 - l[i - 1] + 1) + (r[i + 1] - (i + 1) + 1)
			if sd == r[i + 1]:
				ans2 = 1 + (i - 1 - l[i - 1] + 1) + (r[i + 1] - (i + 1))
			else:
				ans2 = 1 + (i - 1 - l[i - 1] + 1) + (r[i + 1] - (i + 1) + 1)
			ans = max(ans1, ans2, ans)
			continue
		if i - 1 in l:
			fd = stack1[0]
			if fd == l[i - 1]:
				ans1 = 1 + (i - 1 - fd)
			else:
				ans1 = 1 + (i - 1 - l[i - 1] + 1)
			ans2 = -1
			if i < stack2[-1]:
				ans2 = 1 + (i - 1 - l[i - 1] + 1)
			ans = max(ans1, ans, ans2)
			continue
		if i + 1 in r:
			sd = stack2[-1]
			if sd == r[i + 1]:
				ans2 = 1 + (r[i + 1] - (i + 1))
			else:
				ans2 = 1 + (r[i + 1] - (i + 1) + 1)
			ans1 = -1
			if len(stack1) > 0:
				if i > stack1[0]:
					ans1 = 1 + (r[i + 1] - (i + 1) + 1)
			ans = max(ans, ans1, ans2)
			continue
print(ans)


import array
a = array.array('i')
su = [0] * 100000
n = int(input())
s = input()
count = 0
ss = 0
gg = 0
g = 0
for i in range(0, n):
	if s[i] == 'S':
		if count != 0:
			a.append(count)
			gg += 1
		if i > 0 and s[i - 1] == 'S':
			ss = 1
			a.append(0)
		count = 0
	elif i == n - 1:
		count += 1
		gg += 1
		g += 1
		a.append(count)
	else:
		count += 1
		g += 1
if len(a) == 1:
	print(a[0])
elif len(a) == 0:
	print(0)
else:
	for i in range(1, len(a)):
		su[i - 1] = a[i] + a[i - 1]
	su.sort(reverse=True)
	print(su[0] + (1 if (gg > 2 or (gg > 1 and ss == 1)) and g > su[0] else 0))


n = int(input())
s = list(input())
masG = []
masS = []
k = 1
if s[0] == 'S':
	q = True
else:
	q = False
for i in range(n - 1):
	if s[i] == s[i + 1]:
		k += 1
	elif s[i] == 'S':
		masS.append(k)
		k = 1
	else:
		masG.append(k)
		k = 1
if s[-2] == 'S':
	if s[-1] == 'S':
		masS += [k]
	else:
		if k != 1:
			masS += [k]
		masG += [1]
elif s[-1] == 'G':
	masG += [k]
else:
	if k != 1:
		masG += [k]
	masS += [1]
if len(masG) == 0:
	print(0)
	exit()
if len(masG) == 1:
	print(masG[0])
	exit()
if len(masG) == 2:
	if not q:
		if masS[0] == 1:
			print(sum(masG))
		else:
			print(max(masG) + 1)
	elif masS[1] == 1:
		print(sum(masG))
	else:
		print(max(masG) + 1)
	exit()
masS += [1]
ans = 0
if not q:
	for i in range(len(masG) - 1):
		if masS[i] == 1:
			ans = max(ans, masG[i] + masG[i + 1] + 1)
		else:
			ans = max(ans, masG[i] + 1)
	ans = max(ans, masG[-1] + 1)
else:
	for i in range(len(masG) - 1):
		if masS[i + 1] == 1:
			ans = max(ans, masG[i] + masG[i + 1] + 1)
		else:
			ans = max(ans, masG[i] + 1)
	ans = max(ans, masG[-1] + 1)
print(ans)


n = int(input())
s = input()
g1 = 0
g2 = 0
ans = 0
num2 = s.count('G')
for i in range(n):
	if s[i] == 'G':
		g1 += 1
	else:
		g2 = g1
		g1 = 0
	num = g1 + g2
	if num2 != num:
		num += 1
	ans = max(ans, num)
print(min(n, ans))


n = int(input())
s = input()
(R, L) = ([0] * n, [0] * n)
for i in range(n - 1, -1, -1):
	if s[i] == 'G':
		R[i] = 1
		if i < n - 1:
			R[i] += R[i + 1]
for i in range(n):
	if s[i] == 'G':
		L[i] = 1
		if i > 0:
			L[i] += L[i - 1]
ans = 0
for i in range(n):
	if s[i] == 'S':
		z = 1
		if i > 0:
			z += L[i - 1]
		if i < n - 1:
			z += R[i + 1]
		if z > ans:
			ans = z
z = s.count('G')
ans = min(ans, z)
if z == n:
	ans = n
print(ans)


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)


input()
a = p = c = o = 0
for i in input():
	if i == 'G':
		c += 1
		a += 1
	else:
		p = c
		c = 0
	o = max(o, p + c + 1)
print(min(o, a))


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)