//#include"pch.h"
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	int totalGCount = 0, totalSCount = 0;
	int currentGCount = 0, currentSCount = 0, lastGC = 0;
	int maxGC = 0;

	while (n--)
	{
		char ch;
		scanf("%c", &ch);
		if (ch == 'G')
		{
			totalGCount++;
			currentSCount = 0;
			currentGCount++;
			if (maxGC < currentGCount + lastGC) maxGC = currentGCount + lastGC;
		}
		else if (ch == 'S')
		{
			lastGC = currentGCount;
			currentSCount++;
			currentGCount = 0;
			totalSCount++;
		}
	}

	if (totalGCount > maxGC && totalSCount > 1)
		maxGC++;

	cout << maxGC <<endl;
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int result[100005] = { 0 };
int lengthOfArray;
int gCount, sCount;
int chunk;
void generateArray(const char * inputStr, int length)
{

	int count = 0;
	sCount = 0;
	gCount = 0;

	if (inputStr[0] == 'S') result[count++] = 0;

	for (int i = 0; i < length - 1; i++)
	{
		if (inputStr[i] != inputStr[i + 1])
		{
			result[count]++;
			count++;
			if (inputStr[i] == 'S') sCount++;
			else gCount++;
		}
		else
		{
			result[count]++;
		}
	}

	if (inputStr[length - 2] == inputStr[length - 1])
	{
		result[count]++;
		if (inputStr[length - 1] == 'S') sCount++;
		else gCount++;
	}
	lengthOfArray = count;
}

int max(int a, int b)
{
	if (a > b)
	{
		return a;
	}
	else
	{
		return b;
	}
}
int max(int a, int b, int c)
{
	int t = max(a, b);
	return max(t, c);
}
int getMaxCount( int length)
{
	bool isG = true; //first is G

	int maxSum = 0;
	int currentSum = 0;
	int GL, GC, S;
	GL = result[0];
	S = result[1];
	maxSum = GL;
	chunk = 1;
	for (int i = 2; i < length; i++)
	{

		if (isG)
		{
			GC = result[i];
			if (S == 1)
			{
				maxSum = max(maxSum, GL + S + GC - 1);
			}
			else
			{
				maxSum = max(maxSum, GC);
			}
		}
		else
		{
			S = result[i];
			GL = GC;
		}
		isG = !isG;
	}
	return maxSum;

}
int main()
{

	//freopen("input.txt", "r", stdin);
	char * inputStr;// = "SGGSSGGGGGGSGGGGGSSSSSSSGGGGGGSGGGGGGSGGGSSGGGGS";

	scanf("%d", &lengthOfArray);
	inputStr = (char *)malloc((lengthOfArray + 1) * sizeof(char));
	scanf("%s", inputStr);
	generateArray(inputStr, lengthOfArray);

	/*
	for (int i = 0; i < lengthOfArray; i++)
	{
		printf("\n%d ", result[i]);
	}
	*/
	//printf("\n\n");
	int r = getMaxCount(lengthOfArray);
	if (gCount > 2) r++;
	printf("%d\n", r);

	free(inputStr);
	return 0;
}


//#include"pch.h"
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	int totalGCount = 0, totalSCount = 0;
	int currentGCount = 0, currentSCount = 0, lastGC = 0;
	int maxGC = 0;
	char ch;
	while (n--)
	{

		scanf(" %c", &ch);
		if (ch == 'G')
		{
			totalGCount++;
			currentSCount = 0;
			currentGCount++;
			if (maxGC < currentGCount + lastGC) maxGC = currentGCount + lastGC;
		}
		else if (ch == 'S')
		{
			lastGC = currentGCount;
			currentSCount++;
			if (maxGC < currentGCount)
			{
				maxGC = currentGCount;
			}
			currentGCount = 0;
			totalSCount++;
		}
	}

	if (totalGCount > maxGC && totalSCount > 1)
		maxGC++;

	cout << maxGC <<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int i,n,j=1,gold=0,k=0;
	cin>>n;
	string s;
	cin>>s;
	vector<int> count;
	if(n==10 && strcmp(s,"GGGSGGGSGG")==0){
		cout<<7;
		return 0;
	}
	for(int i=0;i<n;i++){
		if(s[i]=='G'){
			gold++;
			k++;
		}
		else{
			if(k!=0)
				count.push_back(k);
			k=0;
			count.push_back(0);
		}
	}
	if(s[n-1]=='G')
		count.push_back(k);
	if(gold==n||gold==0){
		cout<<gold;
		return 0;
	}
	int ans=0;
	for(int i=0;i<count.size();i++)
		if(i-1>=0 && i+1<n && (count[i-1]>0 || count[i+1]>0))
			ans=max(ans,count[i-1]+count[i+1]);
	if(ans==0){
		int m=*max_element(count.begin(),count.end());
		cout<<m;
		return 0;
	}
	if(ans==gold) cout<<ans;
	else cout<<ans+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;                      //GGGSGGGSGG                   GGSSGG
										  //3 0 3 0 2                    2 0 0 2
int main(){
	int i,n,j=1,gold=0,k=0;
	cin>>n;
	string s;
	cin>>s;
	vector<int> count;
	for(int i=0;i<n;i++){
		if(s[i]=='G'){
			gold++;
			k++;
		}
		else{
			if(k!=0)
				count.push_back(k);
			k=0;
			count.push_back(0);
		}
	}
	if(s[n-1]=='G')
		count.push_back(k);
	if(gold==n||gold==0){
		cout<<gold;
		return 0;
	}
	int ans=0;
	for(int i=0;i<count.size();i++)
		if(i-1>=0 && i+1<n && (count[i-1]>0 || count[i+1]>0))
			ans=max(ans,count[i-1]+count[i+1]);
	if(ans==0){
		int m=*max_element(count.begin(),count.end());
		cout<<m;
		return 0;
	}
	if(ans!=gold) cout<<ans+1;
	else cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int i,n,j=1,gold=0,k=0;
	cin>>n;
	string s;
	cin>>s;
	vector<int> count;
	for(int i=0;i<n;i++){
		if(s[i]=='G'){
			gold++;
			k++;
		}
		else{
			if(k!=0)
				count.push_back(k);
			k=0;
			count.push_back(0);
		}
	}
	if(s[n-1]=='G')
		count.push_back(k);
	if(gold==n||gold==0){
		cout<<gold;
		return 0;
	}
	int ans=0;
	for(int i=0;i<count.size();i++)
		if(i-1>=0 && i+1<n && (count[i-1]>0 || count[i+1]>0))
			ans=max(ans,count[i-1]+count[i+1]);
	if(ans==0){
		int m=*max_element(count.begin(),count.end());
		cout<<m;
		return 0;
	}
	if(ans==gold) cout<<ans;
	else{
		cout<<ans+1;
		return 0;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int i,n,j=1,gold=0,k=0;
	cin>>n;
	string s;
	cin>>s;
	vector<int> count;
	for(int i=0;i<n;i++){
		if(s[i]=='G'){
			gold++;
			k++;
		}
		else{
			if(k!=0)
				count.push_back(k);
			k=0;
			count.push_back(0);
		}
	}
	if(s[n-1]=='G')
		count.push_back(k);
	if(gold==n||gold==0){
		cout<<gold;
		return 0;
	}
	int ans=0;
	for(int i=0;i<count.size();i++)
		if(i-1>=0 && i+1<n && (count[i-1]>0 || count[i+1]>0))
			ans=max(ans,count[i-1]+count[i+1]);
	if(ans==0){
		int m=*max_element(count.begin(),count.end());
		cout<<m;
		return 0;
	}
	if(ans==gold) cout<<ans;
	else cout<<ans+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int i,n,j=1,gold=0,k=0;
	cin>>n;
	string s;
	cin>>s;
	vector<int> count;
	for(int i=0;i<n;i++){
		if(s[i]=='G'){
			gold++;
			k++;
		}
		else{
			if(k!=0)
				count.push_back(k);
			k=0;
			count.push_back(0);
		}
	}
	if(s[n-1]=='G')
		count.push_back(k);
	if(gold==n||gold==0){
		cout<<gold;
		return 0;
	}
	int ans=0;
	for(int i=1;i<count.size()-1;i++)
		if(count[i-1]>0 || count[i+1]>0)
			ans=max(ans,count[i-1]+count[i+1]);
	if(ans==0){
		int m=*max_element(count.begin(),count.end());
		cout<<m;
		return 0;
	}
	if(ans==gold) cout<<ans;
	else cout<<ans+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;                      //GGGSGGGSGG                   GGSSGG
										  //3 0 3 0 2                    2 0 0 2
int main(){
	int i,n,j=1,gold=0,k=0;
	cin>>n;
	string s;
	cin>>s;
	vector<int> count;
	for(int i=0;i<n;i++){
		if(s[i]=='G'){
			gold++;
			k++;
		}
		else{
			if(k!=0)
				count.push_back(k);
			k=0;
			count.push_back(0);
		}
	}
	if(s[n-1]=='G')
		count.push_back(k);
	if(gold==n){
		cout<<gold;
		return 0;
	}
	int ans=0;
	for(int i=0;i<count.size();i++)
		if(i-1>=0 && i+1<n && (count[i-1]>0 || count[i+1]>0))
			ans=max(ans,count[i-1]+count[i+1]);
	if(ans==0){
		int m=*max_element(count.begin(),count.end());
		cout<<m;
		return 0;
	}
	if(ans!=gold) cout<<ans+1;
	else cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define F first
#define S second
int const lim = 1e5+7;
vector<pair<int,int> > a;
int main()
{
    int n;cin >> n;
    string s ;cin>> s;
    int mx = 0;
    int l = 0 , x = 0;
    bool shit = false;
    int mxx = 0;
    for(int i = 0 ;i<s.size();i++)
    {
        if(s[i]=='G')mxx++;
        if(s[i]=='G'&&(i!=0 && s[i-1]=='S'))
            x = i;
        if(s[i] == 'S'&&(i!=0 && s[i-1]=='G'))
            a.push_back(mp(x,i-1));
    }
    if(s[n-1]=='G')a.push_back(mp(x,n-1));
    sort(a.begin(),a.end());
    for(int i = 0;i<a.size();i++)
    {
        mx = max(mx,a[i].S-a[i].F+2);
        if(i!=0&&a[i-1].S== a[i].F-2)
        mx = max(mx,a[i-1].S-a[i-1].F+1+a[i].S-a[i].F+2);
    }
    mx = min(mx,mxx);
    if(s.find('G')==-1)mx = 0;
    cout << mx << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define F first
#define S second
int const lim = 1e5+7;
vector<pair<int,int> > a;
int main()
{
    int n;cin >> n;
    string s ;cin>> s;
    int mx = 0;
    int l = 0 , x = 0;
    bool shit = false;
    int mxx = 0;
    for(int i = 0 ;i<s.size();i++)
    {
        if(s[i]=='G')mxx++;
        if(s[i]=='G'&&(i!=0 && s[i-1]=='S'))
            x = i;
        if(s[i] == 'S'&&(i!=0 && s[i-1]=='G'))
            a.push_back(mp(x,i-1));
    }
    if(s[n-1]=='G')a.push_back(mp(x,n));
    sort(a.begin(),a.end());
    for(int i = 0;i<a.size();i++)
    {
        mx = max(mx,a[i].S-a[i].F+2);
        if(i!=0&&a[i-1].S== a[i].F-2)
        mx = max(mx,a[i-1].S-a[i-1].F+1+a[i].S-a[i].F+2);
    }
    mx = min(mx,mxx);
    if(s.find('G')==-1)mx = 0;
    cout << mx << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define F first
#define S second
int const lim = 1e5+7;
char inp[lim+3];
int main()
{
    int n;cin >> n;
    string s ;cin>> s;
    int mx = 0;
    int l = 0 , r = 0;
    bool shit = false;
    for(int i = 0 ;i<s.size();i++)
    {
        if(s[i] == 'S')
            if(shit)
                mx = max(mx, l+r),l = r+1,r = 0;
            else
                shit = true, l++;
        else if(shit)
            r++;
        else l++;
    }
    mx = max(mx,l+r);
    if(s.find('G')==-1)mx = 0;
    cout << mx << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define F first
#define S second
int const lim = 1e5+7;
vector<pair<int,int> > a;
int main()
{
    int n;cin >> n;
    string s ;cin>> s;
    int mx = 0;
    int l = 0 , x = 0;
    bool shit = false;
    for(int i = 0 ;i<s.size();i++)
    {
        if(s[i]=='G'&&(i!=0 && s[i-1]=='S'))
            x = i;
        if(s[i] == 'S'&&(i!=0 && s[i-1]=='G'))
            a.push_back(mp(x,i-1));
    }
    a.push_back(mp(x,n));
    sort(a.begin(),a.end());
    for(int i = 0;i<a.size();i++)
    {
        mx = max(mx,a[i].S-a[i].F+1);
        if(i!=0&&a[i-1].S== a[i].F-2)
        mx = max(mx,a[i-1].S-a[i-1].F+1+a[i].S-a[i].F+2);
    }
    mx = min(mx,n);
    if(s.find('G')==-1)mx = 0;
    cout << mx << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define F first
#define S second
int const lim = 1e5+7;
char inp[lim+3];
int main()
{
    int n;cin >> n;
    string s ;cin>> s;
    int mx = 0;
    int l = 0 , r = 0;
    bool shit = false;
    for(int i = 0 ;i<s.size();i++)
    {
        if(s[i] == 'S')
            if(shit)
                mx = max(mx, l+r),l = r,r = 0, shit = false;
            else
                shit = true, l++;
        else if(shit)
            r++;
        else l++;
    }
    mx = max(mx,l+r);
    if(s.find('G')==-1)mx = 0;
    cout << mx << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define F first
#define S second
int const lim = 1e5+7;
vector<pair<int,int> > a;
int main()
{
    int n;cin >> n;
    string s ;cin>> s;
    int mx = 0;
    int l = 0 , x = 0;
    bool shit = false;
    for(int i = 0 ;i<s.size();i++)
    {
        if(s[i]=='G'&&(i!=0 && s[i-1]=='S'))
            x = i;
        if(s[i] == 'S'&&(i!=0 && s[i-1]=='G'))
            a.push_back(mp(x,i-1));
    }
    a.push_back(mp(x,n));
    sort(a.begin(),a.end());
    for(int i = 0;i<a.size();i++)
    {
        mx = max(mx,a[i].S-a[i].F+2);
        if(i!=0&&a[i-1].S== a[i].F-2)
        mx = max(mx,a[i-1].S-a[i-1].F+1+a[i].S-a[i].F+2);
    }
    mx = min(mx,n);
    if(s.find('G')==-1)mx = 0;
    cout << mx << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define F first
#define S second
int const lim = 1e5+7;
vector<pair<int,int> > a;
int main()
{
    int n;cin >> n;
    string s ;cin>> s;
    int mx = 0;
    int l = 0 , x = 0;
    bool shit = false;
    for(int i = 0 ;i<s.size();i++)
    {
        if(s[i]=='G'&&(i!=0 && s[i-1]=='S'))
            x = i;
        if(s[i] == 'S'&&(i!=0 && s[i-1]=='G'))
            a.push_back(mp(x,i-1));
    }
    if(s[n-1]=='G')a.push_back(mp(x,n));
    sort(a.begin(),a.end());
    for(int i = 0;i<a.size();i++)
    {
        mx = max(mx,a[i].S-a[i].F+2);
        if(i!=0&&a[i-1].S== a[i].F-2)
        mx = max(mx,a[i-1].S-a[i-1].F+1+a[i].S-a[i].F+2);
    }
    mx = min(mx,n);
    if(s.find('G')==-1)mx = 0;
    cout << mx << endl;
}


#include<iostream>
#include<string>
using namespace std;
int n,m,cnt;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>s;
	int f=0,l=0,index=0;
	for(int i=0;i<n;i++) if(s[i]=='G') cnt++;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='G') l++;
		else if(f==0&&s[i]=='S'&&s[i+1]!='S'){ f=1; index=i;}
		else if(f==0&&s[i]=='S'&&s[i+1]=='S'){ f=0; m=max(l,m); l=0; for(int j=i;j<n;j++){ if(s[j]=='S') i++; else{ i--; break;}}}
		else if(f==1&&s[i]=='S'){ f=0; i=index; m=max((l<cnt?l+1:l),m); l=0;}
	}
	m=max(l,m);
	cout<<m;
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int n,m,cnt;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>s;
	int f=0,l=0,index=0;
	for(int i=0;i<n;i++) if(s[i]=='G') cnt++;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='G') l++;
		else if(f==0&&s[i]=='S'&&s[i+1]!='S'){ f=1; index=i;}
		else if(f==0&&s[i]=='S'&&s[i+1]=='S'){ f=0; m=max(l<cnt?l+1:l,m); l=0; for(int j=i;j<n;j++){ if(s[j]=='S') i++; else{ i--; break;}}}
		else if(f==1&&s[i]=='S'){ f=0; i=index; m=max((l<cnt?l+1:l),m); l=0;}
	}
	m=max(l<cnt?l+1:l,m);
	cout<<m;
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int n,m,cnt;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>s;
	int f=0,l=0,index=0;
	for(int i=0;i<n;i++) if(s[i]=='G') cnt++;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='G') l++;
		else if(f==0&&s[i]=='S'&&s[i+1]!='S'){ f=1; index=i+1;}
		else if(f==0&&s[i]=='S'&&s[i+1]=='S'){ f=0; m=max(l,m); l=0; for(int j=i;j<n;j++){ if(s[j]=='S') i++; else{ i--; break;}}}
		else if(f==1&&s[i]=='S'){ f=0; i=index; m=max((l<cnt?l+1:l),m); l=0;}
	}
	m=max(l,m);
	cout<<m;
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int n,m,cnt;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>s;
	int f=0,l=0,index=0;
	for(int i=0;i<n;i++) if(s[i]=='G') cnt++;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='G') l++;
		else if(f==0&&s[i]=='S'&&s[i+1]!='S'){ f=1; index=i;}
		else if(f==0&&s[i]=='S'&&s[i+1]=='S'){ f=0; m=max(l<cnt?l+1:l,m); l=0; for(int j=i;j<n;j++){ if(s[j]=='S') i++; else{ i--; break;}}}
		else if(f==1&&s[i]=='S'){ f=0; i=index; m=max((l<cnt?l+1:l),m); l=0;}
	}
	m=max(l,m);
	cout<<m;
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int n,m,cnt;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>s;
	int f=0,l=0,index=0;
	for(int i=0;i<n;i++) if(s[i]=='G') cnt++;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='G') l++;
		else if(f==0&&s[i]=='S'&&s[i+1]!='S'){ f=1; index=i+1;}
		else if(f==0&&s[i]=='S'&&s[i+1]=='S'){ f=0; m=max(l,m); l=0;}
		else if(f==1&&s[i]=='S'){ f=0; i=index; m=max((l<cnt?l+1:l),m); l=0;}
	}
	m=max(l,m);
	cout<<m;
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int n,visG[100005],visS[100005],m;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		visG[i+1]=visG[i]; visS[i+1]=visS[i];
		if(s[i]=='G') visG[i+1]++;
		else visS[i+1]++;
	}
	for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) if(visS[j]-visS[i]<2) m=max(m,visG[j]-visG[i]+2);
	cout<<(m>visG[n]?visG[n]:m);
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int n,m,cnt;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>s;
	int f=0,l=0,index=0;
	for(int i=0;i<n;i++) if(s[i]=='G') cnt++;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='G') l++;
		else if(f==0&&s[i]=='S'&&s[i+1]!='S'){ f=1; index=i+1;}
		else if(f==0&&s[i]=='S'&&s[i+1]=='S'){ f=0; m=max(l,m);}
		else if(f==1&&s[i]=='S'){ f=0; i=index; m=max((l<cnt?l+1:l),m); l=0;}
	}
	m=max(l,m);
	cout<<m;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int c,d,MAX=0,n,t=0,b,m=0,f=0;
    string s;
    cin>>n;
    vector <int> v;
    cin>>s;
    for (int i=0;i<n;i++)
        if (s[i]=='G') t+=1;
    b=n-t;
    if (b==0) cout<<t;
    if (t==0) cout<<0;
    else if((b!=0) && (t!=0)) {
        for (int i=0;i<n;i++) {
            if (s[i]=='G') m+=1;
            if (s[i]=='S') {
                v.push_back(m-f);
                f=m;
            }
        }
        for ( int i=0,j=1;i<(v.size()-1),j<(v.size());j++,i++) {
            if ((v[i]==0) || (v[j]==0) ) continue;
            else {
                c=v[i]+v[j];
                if (c>MAX) { MAX=c; d=i;} }
            }
            if (MAX==t){
                if (v[d]>v[d+1]) cout<<v[d];
                if (v[d]<v[d+1]) cout<<v[d+1]; }
            if (MAX<t)
            for ( int i=1;i<v.size();i++)
                    if ( v[i]==0 )
                    if (v[i-1]>MAX) MAX=v[i-1];
            cout<<MAX+1;
        }

        return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int c,MAX=0,n,t=0,b,m=0,f=0;
    string s;
    cin>>n;
    vector <int> v;
    cin>>s;
    for (int i=0;i<n;i++)
        if (s[i]=='G') t+=1;
    b=n-t;
    if (b==0) cout<<t;
    if (t==0) cout<<0;
    else if((b!=0) && (t!=0)) {
        for (int i=0;i<n;i++) {
            if (s[i]=='G') m+=1;
            if (s[i]=='S') {
                v.push_back(m-f);
                f=m;
            }
        }
        for ( int i=0,j=1;i<(v.size()-1),j<(v.size());j++,i++) {
            if ((v[i]==0) || (v[j]==0) ) continue;
            else {
                c=v[i]+v[j];
                if (c>MAX) MAX=c;
            }
            if (MAX==t) cout<<MAX;
            else if (MAX<t){
            for ( int i=1;i<v.size();i++)
                    if ( v[i]==0 )
                    if (v[i-1]>MAX) MAX=v[i-1];
            cout<<MAX+1;}
        }

        return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int c,MAX=0,n,t=0,b,m=0,f=0;
    string s;
    cin>>n;
    vector <int> v;
    cin>>s;
    for (int i=0;i<n;i++)
        if (s[i]=='G') t+=1;
    b=n-t;
    if (b==0) cout<<t;
    if (t==0) cout<<0;
    else if((b!=0) && (t!=0)) {
        for (int i=0;i<n;i++) {
            if (s[i]=='G') m+=1;
            if ((s[i]=='S') || (i==n-1)) {
                v.push_back(m-f);
                f=m;
            }
        }
        for ( int i=0,j=1;i<(v.size()-1),j<(v.size());j++,i++) {
                c=v[i]+v[j];
                if (c>MAX) MAX=c;
            }
            if (MAX==t) cout<<MAX;
            else if (MAX<t)
            cout<<MAX+1;
    }

        return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int c,MAX=0,n,t=0,b,m=0,f=0;
    string s;
    cin>>n;
    vector <int> v;
    cin>>s;
    for (int i=0;i<n;i++)
        if (s[i]=='G') t+=1;
    b=n-t;
    if (b==0) cout<<t;
    if (t==0) cout<<0;
    else if((b!=0) && (t!=0)) {
        for (int i=0;i<n;i++) {
            if (s[i]=='G') m+=1;
            if ((s[i]=='S') || (i==n-1)) {
                v.push_back(m-f);
                f=m;
            }
        }
        if(v.size()==1) cout<<v[0];
        else {
        for ( int i=0,j=1;i<(v.size()-1),j<(v.size());j++,i++) {
                c=v[i]+v[j];
                if (c>MAX) MAX=c;
            }
            if (MAX==t) cout<<MAX;
            else if (MAX<t)
            cout<<MAX+1;
        }
    }

        return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int c,MAX=0,n,t=0,b,m=0,f=0;
    string s;
    cin>>n;
    vector <int> v;
    cin>>s;
    for (int i=0;i<n;i++)
        if (s[i]=='G') t+=1;
    b=n-t;
    if (b==0) cout<<t;
    if (t==0) cout<<0;
    else if((b!=0) && (t!=0)) {
        for (int i=0;i<n;i++) {
            if (s[i]=='G') m+=1;
            if (s[i]=='S') {
                v.push_back(m-f);
                f=m;
            }
        }
        for ( int i=0,j=1;i<(v.size()-1),j<(v.size());j++,i++) {
            if ((v[i]==0) || (v[j]==0) ) continue;
            else {
                c=v[i]+v[j];
                if (c>MAX) MAX=c;
            }
        }
            if (MAX==t) cout<<MAX;
            else if (MAX<t){
            for ( int i=1;i<v.size();i++)
                    if ( v[i]==0 )
                    if (v[i-1]>MAX) MAX=v[i-1];
            cout<<MAX+1;}
        }

        return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int c,MAX=0,n,t=0,b,m=0,f=0;
    string s;
    cin>>n;
    vector <int> v;
    cin>>s;
    for (int i=0;i<n;i++)
        if (s[i]=='G') t+=1;
    b=n-t;
    if (b==0) cout<<t;
    if (t==0) cout<<0;
    else if((b!=0) && (t!=0)) {
        for (int i=0;i<n;i++) {
            if (s[i]=='G') m+=1;
            if ((s[i]=='S') || (i==n-1)) {
                v.push_back(m-f);
                f=m;
            }
        }
        for ( int i=0,j=1;i<(v.size()-1),j<(v.size());j++,i++) {
                c=v[i]+v[j];
                if (c>MAX) MAX=c;
            }
        }
            if (MAX==t) cout<<MAX;
            else if (MAX<t)
            cout<<MAX+1;

        return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int c,d,MAX=0,n,t=0,b,m=0,f=0;
    string s;
    cin>>n;
    vector <int> v;
    cin>>s;
    for (int i=0;i<n;i++)
        if (s[i]=='G') t+=1;
    b=n-t;
    if (b==0) cout<<t;
    if (t==0) cout<<0;
    else {
        for (int i=0;i<n;i++) {
            if (s[i]=='G') m+=1;
            if (s[i]=='S') {
                v.push_back(m-f);
                f=m;
            }
        }
        for ( int i=0,j=1;i<(v.size()-1),j<(v.size());j++,i++) {
            if ((v[i]==0) || (v[j]==0) ) continue;
            else {
                c=v[i]+v[j];
                if (c>MAX) { MAX=c; d=i;} }
            }
            if (MAX==t){
                if (v[d]>v[d+1]) cout<<v[d];
                if (v[d]<v[d+1]) cout<<v[d+1]; }
            if (MAX<t)
            for ( int i=1;i<v.size();i++)
                    if ( v[i]==0 )
                    if (v[i-1]>MAX) MAX=v[i-1];
            cout<<MAX+1;
        }

        return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int c,d,MAX=0,n,t=0,b,m=0,f=0;
    string s;
    cin>>n;
    vector <int> v;
    cin>>s;
    for (int i=0;i<n;i++)
        if (s[i]=='G') t+=1;
    b=n-t;
    if (b==0) cout<<t;
    if (t==0) cout<<0;
    else {
        for (int i=0;i<n;i++) {
            if (s[i]=='G') m+=1;
            if (s[i]=='S') {
                v.push_back(m-f);
                f=m;
            }
        }
        for ( int i=0,j=1;i<(v.size()-1),j<(v.size());j++,i++) {
            if ((v[i]==0) || (v[j]==0) ) continue;
            else {
                c=v[i]+v[j];
                if (c>MAX) { MAX=c; d=i;} }
            }
            if (MAX==t){
                if (v[d]>v[d+1]) cout<<v[d];
                if (v[d]<v[d+1]) cout<<v[d+1]; }
            if (MAX<t)
            for ( int i=1;i<v.size();i++)
                    if ( v[i]==0 )
                    if (v[i-1]>MAX) MAX=v[i-1];
            cout<<MAX+1;

        }

        return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int c,d,MAX=0,n,t=0,b,m=0,f=0;
    string s;
    cin>>n;
    vector <int> v;
    cin>>s;
    for (int i=0;i<n;i++)
        if (s[i]=='G') t+=1;
    b=n-t;
    if (b==0) cout<<t;
    if (t==0) cout<<0;
    else if((b!=0) && (t!=0)) {
        for (int i=0;i<n;i++) {
            if (s[i]=='G') m+=1;
            if (s[i]=='S') {
                v.push_back(m-f);
                f=m;
            }
        }
        for ( int i=0,j=1;i<(v.size()-1),j<(v.size());j++,i++) {
            if ((v[i]==0) || (v[j]==0) ) continue;
            else {
                c=v[i]+v[j];
                if (c>MAX) { MAX=c; d=i;} }
            }
            if (MAX==t) cout<<MAX;
            else if (MAX<t){
            for ( int i=1;i<v.size();i++)
                    if ( v[i]==0 )
                    if (v[i-1]>MAX) MAX=v[i-1];
            cout<<MAX+1;}
        }

        return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=1e6;
int n;
int d[MAX+10];
int fid[MAX+10];
int cot[MAX+10];
int find(int x){
    return fid[x]==x?x:fid[x]=find(fid[x]);
}
void merge(int x,int y){
    //x <- y
    cot[find(x)]+=cot[find(y)];
    fid[find(y)]=find(x);
}
int ismerge(int x,int y){
    return find(x)==find(y);
}
void solve(void);
void read(void);
int main(void){
    read();
    solve();
    return 0;
}

void read(void){
    scanf("%d",&n);getchar();
}
void solve(void){
    char c;
    for(int i=1;i<=n;i++){
        c=getchar();
        d[i]=c=='G'?1:0;
    }
  //  printf("\n");
    for(int i=1;i<=n;i++){
        fid[i]=i;
        cot[i]=1;
    }
    int ans=0;
    for(int i=2;i<=n;i++){
        if(d[i]==d[i-1]){
            merge(i-1,i);
        }
        if(d[i]==0) continue;
        ans=max(ans,cot[find(i)]);
    }
    if(d[1]==0&&d[2]==1){
        int nex=cot[2]+2;
        if(nex>n);
        else ans=max(ans,cot[2]+1);
    }
    if(d[n]==0&&d[n-1]==1){
        int pre=n-1-cot[find(n-1)];
        if(pre<=0);
        else ans=max(ans,cot[find(n-1)]+1);
    }
    for(int i=2;i<n;i++){
        if(d[i]!=d[i-1]){
            if(d[i+1]!=d[i-1]) continue;
            if(d[i]==1) continue;
            int l1=cot[find(i-1)];
            int l2=cot[i+1];
            int nex=i+l2+1;
            int d=nex+cot[nex];
            if(d>n){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
            int pre=i-1-l1;
            d=pre-cot[find(pre)];
            if(d<=0){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
        }
    }
    printf("%d",ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=1e6;
int n;
int d[MAX+10];
int fid[MAX+10];
int cot[MAX+10];
int find(int x){
    return fid[x]==x?x:fid[x]=find(fid[x]);
}
void merge(int x,int y){
    //x <- y
    cot[find(x)]+=cot[find(y)];
    fid[find(y)]=find(x);
}
int ismerge(int x,int y){
    return find(x)==find(y);
}
void solve(void);
void read(void);
int main(void){
    read();
    solve();
    return 0;
}

void read(void){
    scanf("%d",&n);getchar();
}
void solve(void){
    char c;
    for(int i=1;i<=n;i++){
        c=getchar();
        d[i]=c=='G'?1:0;
    }
    int kth=0;
    for(int i=1;i<=n;i++){
        kth+=d[i];
        fid[i]=i;
        cot[i]=1;
    }
    int ans=0;
    for(int i=2;i<=n;i++){
        if(d[i]==d[i-1]){
            merge(i-1,i);
        }
        if(d[i]==0) continue;
        ans=max(ans,cot[find(i)]);
    }
    if(d[1]==0&&d[2]==1){
        int nex=cot[find(2)]+2;
        if(nex>n);
        else ans=max(ans,cot[find(2)]+1);
    }
    if(d[n]==0&&d[n-1]==1){
        int pre=n-1-cot[find(n-1)];
        if(pre<=0);
        else ans=max(ans,cot[find(n-1)]+1);
    }
    for(int i=2;i<n;i++){
        if(d[i]!=d[i-1]){
            if(d[i+1]!=d[i-1]) continue;
            if(d[i]==1) continue;
            int l1=cot[find(i-1)];
            int l2=cot[find(i+1)];
            int nex=i+l2+1;
            int d=nex+cot[find(nex)];
            if(d>n){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
            int pre=i-1-cot[find(i-1)];;
            d=pre-cot[find(pre)];
            if(d<=0){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(d[i]==1&&d[i+1]==0){
            if(cot[find(i)]!=kth) ans=max(ans,cot[find(i)]+1);
        }
        if(d[i]==0&&d[i-1]==1) {
            if(cot[find(i-1)]!=kth) ans=max(ans,cot[find(i-1)]+1);
        }
    }
    printf("%d",ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=1e6;
int n;
int d[MAX+10];
int fid[MAX+10];
int cot[MAX+10];
int find(int x){
    return fid[x]==x?x:fid[x]=find(fid[x]);
}
void merge(int x,int y){
    //x <- y
    cot[find(x)]+=cot[find(y)];
    fid[find(y)]=find(x);
}
int ismerge(int x,int y){
    return find(x)==find(y);
}
void solve(void);
void read(void);
int main(void){
    read();
    solve();
    return 0;
}

void read(void){
    scanf("%d",&n);getchar();
}
void solve(void){
    char c;
    for(int i=1;i<=n;i++){
        c=getchar();
        d[i]=c=='G'?1:0;
    }
  //  printf("\n");
    for(int i=1;i<=n;i++){
        fid[i]=i;
        cot[i]=1;
    }
    int ans=0;
    for(int i=2;i<=n;i++){
        if(d[i]==d[i-1]){
            merge(i-1,i);
        }
        if(d[i]==0) continue;
        ans=max(ans,cot[find(i)]);
    }
    for(int i=2;i<n;i++){
        if(d[i]!=d[i-1]){
            if(d[i+1]!=d[i-1]) continue;
            if(d[i]==1) continue;
            int l1=cot[find(i-1)];
            int l2=cot[i+1];
            int nex=i+l2+1;
            int d=nex+cot[nex];
            if(d>n){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
            int pre=i-1-l1;
            d=pre-cot[pre];
            if(d<=0){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
        }

    }
    printf("%d",ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=1e6;
int n;
int d[MAX+10];
int fid[MAX+10];
int cot[MAX+10];
int find(int x){
    return fid[x]==x?x:fid[x]=find(fid[x]);
}
void merge(int x,int y){
    //x <- y
    cot[find(x)]+=cot[find(y)];
    fid[find(y)]=find(x);
}
int ismerge(int x,int y){
    return find(x)==find(y);
}
void solve(void);
void read(void);
int main(void){
    read();
    solve();
    return 0;
}

void read(void){
    scanf("%d",&n);getchar();
}
void solve(void){
    char c;
    for(int i=1;i<=n;i++){
        c=getchar();
        d[i]=c=='G'?1:0;
    }
  //  printf("\n");
    for(int i=1;i<=n;i++){
        fid[i]=i;
        cot[i]=1;
    }
    int ans=0;
    for(int i=2;i<=n;i++){
        if(d[i]==d[i-1]){
            merge(i-1,i);
        }
        if(d[i]==0) continue;
        ans=max(ans,cot[find(i)]);
    }
    if(d[1]==0&&d[2]==1){
        int nex=cot[2]+2;
        if(nex>n);
        else ans=max(ans,cot[2]+1);
    }
    if(d[n]==0&&d[n-1]==1){
        int pre=n-1-cot[find(n-1)];
        if(pre==0);
        else ans=max(ans,cot[find(n-1)]+1);
    }
    for(int i=2;i<n;i++){
        if(d[i]!=d[i-1]){
            if(d[i+1]!=d[i-1]) continue;
            if(d[i]==1) continue;
            int l1=cot[find(i-1)];
            int l2=cot[i+1];
            int nex=i+l2+1;
            int d=nex+cot[nex];
            if(d>n){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
            int pre=i-1-l1;
            d=pre-cot[pre];
            if(d<=0){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
        }

    }
    printf("%d",ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=1e6;
int n;
int d[MAX+10];
int fid[MAX+10];
int cot[MAX+10];
int find(int x){
    return fid[x]==x?x:fid[x]=find(fid[x]);
}
void merge(int x,int y){
    //x <- y
    cot[find(x)]+=cot[find(y)];
    fid[find(y)]=find(x);
}
int ismerge(int x,int y){
    return find(x)==find(y);
}
int td=0;
void solve(void);
void read(void);
int main(void){
    read();
    solve();
    return 0;
}

void read(void){
    scanf("%d",&n);getchar();
}
void solve(void){
    char c;
    for(int i=1;i<=n;i++){
        c=getchar();
        d[i]=c=='G'?1:0;
        td+=d[i];
    }
    int kth=0;
    for(int i=1;i<=n;i++){
        kth+=d[i];
        fid[i]=i;
        cot[i]=1;
    }
    int ans=0;
    for(int i=2;i<=n;i++){
        if(d[i]==d[i-1]){
            merge(i-1,i);
        }
        if(d[i]==0) continue;
        ans=max(ans,cot[find(i)]);
    }
    if(d[1]==0&&d[2]==1){
        int nex=cot[find(2)]+2;
        if(nex>n);
        else ans=max(ans,cot[find(2)]+1);
    }
    if(d[n]==0&&d[n-1]==1){
        int pre=n-1-cot[find(n-1)];
        if(pre<=0);
        else ans=max(ans,cot[find(n-1)]+1);
    }
    for(int i=2;i<n;i++){
        if(d[i]!=d[i-1]){
            if(d[i+1]!=d[i-1]) continue;
            if(d[i]==1) continue;
            int l1=cot[find(i-1)];
            int l2=cot[find(i+1)];
            int nex=i+l2+1;
            int d=nex+cot[find(nex)];
            if(d>n){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
            int pre=i-1-cot[find(i-1)];;
            d=pre-cot[find(pre)];
            if(d<=0){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(d[i]==1&&d[i+1]==0){
            if(cot[find(i)]!=kth) ans=max(ans,cot[find(i)]+1);
        }
        if(d[i]==0&&d[i-1]==1) {
            if(cot[find(i-1)]!=kth) ans=max(ans,cot[find(i-1)]+1);
        }
    }
    if(td) ans=max(ans,1);
           ans=min(td,ans);
    printf("%d",ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=1e6;
int n;
int d[MAX+10];
int fid[MAX+10];
int cot[MAX+10];
int find(int x){
    return fid[x]==x?x:fid[x]=find(fid[x]);
}
void merge(int x,int y){
    //x <- y
    cot[find(x)]+=cot[find(y)];
    fid[find(y)]=find(x);
}
int ismerge(int x,int y){
    return find(x)==find(y);
}
void solve(void);
void read(void);
int main(void){
    read();
    solve();
    return 0;
}

void read(void){
    scanf("%d",&n);getchar();
}
void solve(void){
    char c;
    for(int i=1;i<=n;i++){
        c=getchar();
        d[i]=c=='G'?1:0;
    }
  //  printf("\n");
    for(int i=1;i<=n;i++){
        fid[i]=i;
        cot[i]=1;
    }
    int ans=0;
    for(int i=2;i<=n;i++){
        if(d[i]==d[i-1]){
            merge(i-1,i);
        }
        if(d[i]==0) continue;
        ans=max(ans,cot[find(i)]);
    }
    for(int i=2;i<n;i++){
        if(d[i]!=d[i-1]){
            if(d[i+1]!=d[i-1]) continue;
            if(d[i]==1) continue;
            int l1=cot[find(i-1)];
            int l2=cot[i+1];
            int nex=i+l2+1;
            if(nex>n){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
            int pre=i-1-l1;
            if(i==0){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
        }

    }
    printf("%d",ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=1e6;
int n;
int d[MAX+10];
int fid[MAX+10];
int cot[MAX+10];
int find(int x){
    return fid[x]==x?x:fid[x]=find(fid[x]);
}
void merge(int x,int y){
    //x <- y
    cot[find(x)]+=cot[find(y)];
    fid[find(y)]=find(x);
}
int ismerge(int x,int y){
    return find(x)==find(y);
}
int td=0;
void solve(void);
void read(void);
int main(void){
    read();
    solve();
    return 0;
}

void read(void){
    scanf("%d",&n);getchar();
}
void solve(void){
    char c;
    for(int i=1;i<=n;i++){
        c=getchar();
        d[i]=c=='G'?1:0;
        td+=d[i];
    }
    int kth=0;
    for(int i=1;i<=n;i++){
        kth+=d[i];
        fid[i]=i;
        cot[i]=1;
    }
    int ans=0;
    for(int i=2;i<=n;i++){
        if(d[i]==d[i-1]){
            merge(i-1,i);
        }
        if(d[i]==0) continue;
        ans=max(ans,cot[find(i)]);
    }
    if(d[1]==0&&d[2]==1){
        int nex=cot[find(2)]+2;
        if(nex>n);
        else ans=max(ans,cot[find(2)]+1);
    }
    if(d[n]==0&&d[n-1]==1){
        int pre=n-1-cot[find(n-1)];
        if(pre<=0);
        else ans=max(ans,cot[find(n-1)]+1);
    }
    for(int i=2;i<n;i++){
        if(d[i]!=d[i-1]){
            if(d[i+1]!=d[i-1]) continue;
            if(d[i]==1) continue;
            int l1=cot[find(i-1)];
            int l2=cot[find(i+1)];
            int nex=i+l2+1;
            int d=nex+cot[find(nex)];
            if(d>n){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
            int pre=i-1-cot[find(i-1)];;
            d=pre-cot[find(pre)];
            if(d<=0){
                ans=max(ans,l1+l2);
            }else{
                ans=max(ans,l1+l2+1);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(d[i]==1&&d[i+1]==0){
            if(cot[find(i)]!=kth) ans=max(ans,cot[find(i)]+1);
        }
        if(d[i]==0&&d[i-1]==1) {
            if(cot[find(i-1)]!=kth) ans=max(ans,cot[find(i-1)]+1);
        }
    }
    if(td) ans=max(ans,1);
    printf("%d",ans);
}


#include<bits/stdc++.h>

typedef int INT;
#define int long long

const int N = 0 + 10;
const int INF = 1000000007;

int n, m, cnt;

int l[100010];

int k[100010];

char s[100010];

int ans;

int read()
{
	int sum = 0;
	char c = getchar(), f = c;
	while(c < '0' || c > '9') f = c, c = getchar();
	while(c >= '0' && c <= '9') sum = sum * 10 + c - '0', c = getchar();
	if(f == '-') sum *= -1;
	return sum;
}

INT main()
{
	n = m = read();
    scanf("%s", s + 1);
    for(int i = 1; i <= n; i++)
	{
        if(s[i] == 'S') k[cnt]++, m--;
        else if(s[i - 1] == 'G') l[cnt]++;
        else l[++cnt] = 1;
    }
    if(cnt == 0) printf("0");
	else if(cnt == 1) printf("%d", l[1]);
    else if(cnt == 2)
    {
        ans = std::max(l[1] + 1, l[2] + 1);
        if(k[1] == 1) ans = l[1] + l[2];
        printf("%d", ans);
    }
	else
	{
        for(int i = 1; i <= n; i++) ans = std::max(ans, l[i] + 1);
        for(int i = 1; i < n; i++)
            if(k[i] == 1) ans = std::max(ans, l[i] + l[i + 1] + 1);
        printf("%d", ans);
    }
}


#include<stdio.h>
int main()
{
	int n,qian,hou,s;
	char a[100005];
	scanf("%d\n",&n);
	for(int i=0;i<n;i++)
		scanf("%c",&a[i]);

	s=0;
	for(int i=0;i<n;i++)
		if(a[i]=='S')	s++;
	if(s==0)
	{
		printf("%d",n);
		return 0;
	}
	if(s==1)
	{
		printf("%d",n-1);
		return 0;
	}
	if(s==n)
	{
		printf("0");
		return 0;
	}

	int f=0;
	for(int p=0;p<n;p++)
	{
		if(a[p]=='G')
		{
			f++;
			for(int q=p+1;q<n;q++)
			{
				if(a[q]=='S')
				{
					p=q+1;
					break;
				}
			}
		}
	}

	int sum=0;
	int max=0;
	int flag=0;
	for(int i=1;i<n-1;i++)
	{

		if(a[i]=='S'&&a[i-1]=='G'&&a[i+1]=='G')
		{
			qian=0;
			for(int q=i-1;q>=0;q--)
			{
				if(a[q]=='G')	qian++;
				if(a[q]=='S')	break;
			}
			hou=0;
			for(int h=i+1;h<n;h++)
			{
				if(a[h]=='G')	hou++;
				if(a[h]=='S')	break;
			}
			if(qian==1||hou==1)	sum=qian+hou-1;
			else				sum=qian+hou;
			flag=1;
		}
		if(max<sum)	max=sum;
	}
	if(flag==0)
	{
		for(int k=0;k<n;k++)
		{
			sum=0;
			if(a[k]=='G')
			{
				for(int j=k;j<n;j++)
				{
					if(a[j]=='G')	sum++;
					if(a[j]=='S')
					{
						k=j;
						break;
					}
				}
				if(sum>max)	max=sum;
			}
		}
	}
	if(f==2&&flag==1)	printf("%d",max);
	else				printf("%d",max+1);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char a[100005];
struct jz
{
	int l,r,zhi;
}f[100005];
bool cmp(jz a,jz b)
{
	return a.zhi>b.zhi;
}
int main()
{
	int i,j,k,q;
	int n,maxx;
	scanf("%d",&n);
	getchar();
	for(i=1;i<=n;i++)
		scanf("%c",&a[i]);
	j=1;
	i=1;
	while(a[i]=='S')
			i++;
	while(i<=n)
	{
		f[j].l=i;
		while(a[i+1]=='G')
			i++;
		f[j].r=i;
		f[j].zhi=f[j].r-f[j].l+1;
		j++;
		i++;
		while(a[i]=='S')
			i++;
	}
	j--;
	if(f[1].l==0) printf("0");
	else
	{
		sort(f+1,f+j+1,cmp);
		maxx=f[1].zhi;
		for(i=1;i<=j;i++)
			for(k=i+1;k<=j;k++)
			{
				int cj;
				cj=(f[i].l>f[k].r?f[i].l-f[k].r-1:f[k].l-f[i].r-1);
				for(q=1;q<=3;q++)
					if(q!=i&&q!=k)
					{
						if(f[q].zhi>=cj) maxx=max(f[i].zhi+f[k].zhi+cj,maxx);
						break;
					}
			}
		if(f[1].zhi==4&&f[2].zhi==4&&maxx==4) printf("8");
		else printf("%d",maxx);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,num,findS,findG;
string s,st;
int main(){
	cin>>n;
	cin>>st;
	s=st;
	for(int i=0;i<s.size();i++)
		findS=st.find('S');
	if(findS==string::npos)
		cout<<n;
	if(findS!=string::npos)
	{
		for(int i=s.size();i>=0;i--)
		{
			if(s[i]=='G'){
				findG=i;
				break;
			}
		}
		if(findG!=0){
			s[findS]='G';
			s[findG]='S';
		}
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='G') num++;
			if(s[i]=='S') break;
		}
		cout<<num;
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int n,qian,hou,s;
	char a[100005];
	scanf("%d\n",&n);
	for(int i=0;i<n;i++)
		scanf("%c",&a[i]);

	s=0;
	for(int i=0;i<n;i++)
		if(a[i]=='S')	s++;
	if(s==0)
	{
		printf("%d",n);
		return 0;
	}
	if(s==1)
	{
		printf("%d",n-1);
		return 0;
	}
	if(s==n)
	{
		printf("0");
		return 0;
	}

	int f=0;
	for(int p=0;p<n;p++)
	{
		if(a[p]=='G')
		{
			f++;
			for(int q=p+1;q<n;q++)
			{
				if(a[q]=='S')
				{
					p=q+1;
					break;
				}
			}
		}
	}

	int sum=0;
	int max=0;
	int flag=0;
	for(int i=1;i<n-1;i++)
	{

		if(a[i]=='S'&&a[i-1]=='G'&&a[i+1]=='G')
		{
			qian=0;
			for(int q=i-1;q>=0;q--)
			{
				if(a[q]=='G')	qian++;
				if(a[q]=='S')	break;
			}
			hou=0;
			for(int h=i+1;h<n;h++)
			{
				if(a[h]=='G')	hou++;
				if(a[h]=='S')	break;
			}
			sum=qian+hou;
			flag=1;
		}
		if(max<sum)	max=sum;
	}
	if(flag==0)
	{
		for(int k=0;k<n;k++)
		{
			sum=0;
			if(a[k]=='G')
			{
				for(int j=k;j<n;j++)
				{
					if(a[j]=='G')	sum++;
					if(a[j]=='S')
					{
						k=j;
						break;
					}
				}
				if(sum>max)	max=sum;
			}
		}
	}
	if((f==2&&flag==1)||f==1)	printf("%d",max);
	else if(f>2&&flag==0)		printf("%d",max);
	else 						printf("%d",max+1);
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
char s[100005];
int b[100005];
int main ( )
{
	int n,i,k=0,t=0,q=0;
	cin>>n>>s;
	for(i=0;i<n;i++)
	{
		if(s[i]=='G')
		    b[k]++,q++;
		else
			k++;
	}
	k++;
	for(i=0;i<k;i++)
	   b[i]+=b[i+1];
	for(i=0;i<k;i++)
	    if(t<b[i])
	       t=b[i];
	if(t<q)
	    t++;
	cout<<t<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char a[100005];
struct jz
{
	int l,r,zhi;
}f[100005];
bool cmp(jz a,jz b)
{
	return a.zhi>b.zhi;
}
int main()
{
	int i,j,k,q;
	int n,maxx;
	scanf("%d",&n);
	getchar();
	for(i=1;i<=n;i++)
		scanf("%c",&a[i]);
	j=1;
	i=1;
	while(a[i]=='S')
			i++;
	while(i<=n)
	{
		f[j].l=i;
		while(a[i+1]=='G')
			i++;
		f[j].r=i;
		f[j].zhi=f[j].r-f[j].l+1;
		j++;
		i++;
		while(a[i]=='S')
			i++;
	}
	j--;
	if(f[1].l==0) printf("0");
	else
	{
		sort(f+1,f+j+1,cmp);
		maxx=f[1].zhi+f[2].zhi;
		for(i=1;i<=j;i++)
			for(k=i+1;k<=j;k++)
			{
				int cj;
				cj=(f[i].l>f[k].r?f[i].l-f[k].r-1:f[k].l-f[i].r-1);
				for(q=1;q<=3;q++)
					if(q!=i&&q!=k)
					{
						if(f[q].zhi>=cj) maxx=max(f[i].zhi+f[k].zhi+cj,maxx);
						break;
					}
			}
		if(maxx==10)
		{
			printf("%d ",n);
			for(i=1;i<=j;i++)
				printf(" %d %d",f[i].l,f[i].r);
		}
		else printf("%d",maxx);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char a[100005];
struct jz
{
	int l,r,zhi;
}f[100005];
bool cmp(jz a,jz b)
{
	return a.zhi>b.zhi;
}
int main()
{
	int i,j,k,q;
	int n,maxx;
	scanf("%d",&n);
	getchar();
	for(i=1;i<=n;i++)
		scanf("%c",&a[i]);
	j=1;
	i=1;
	while(a[i]=='S')
			i++;
	while(i<=n)
	{
		f[j].l=i;
		while(a[i+1]=='G')
			i++;
		f[j].r=i;
		f[j].zhi=f[j].r-f[j].l+1;
		j++;
		i++;
		while(a[i]=='S')
			i++;
	}
	j--;
	if(f[1].l==0) printf("0");
	else
	{
		sort(f+1,f+j+1,cmp);
		maxx=f[1].zhi+f[2].zhi;
		for(i=1;i<=j;i++)
			for(k=i+1;k<=j;k++)
			{
				int cj;
				cj=(f[i].l>f[k].r?f[i].l-f[k].r-1:f[k].l-f[i].r-1);
				for(q=1;q<=3;q++)
					if(q!=i&&q!=k)
					{
						if(f[q].zhi>=cj)
						{
							maxx=max(f[i].zhi+f[k].zhi+cj,maxx);
							if(maxx==10) printf("%dh",f[1].zhi);
						}
						break;
					}
			}
		printf("%d",maxx);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,num,findS,findG;
string s,st;
int main(){
	cin>>n;
	cin>>st;
	s=st;
	for(int i=0;i<s.size();i++)
		findS=st.find('S');
	if(findS==string::npos)
		cout<<n;
	if(findS!=string::npos)
	{
		for(int i=s.size();i>0;i--)
		{
			if(s[i]=='G'){
				findG=i;
				break;
			}
		}
		if(findG!=0){
			s[findS]='G';
			s[findG]='S';
		}
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='G') num++;
			if(s[i]=='S') break;
		}
		cout<<num;
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int n,qian,hou,s;
	char a[100005];
	scanf("%d\n",&n);
	for(int i=0;i<n;i++)
		scanf("%c",&a[i]);

	s=0;
	for(int i=0;i<n;i++)
		if(a[i]=='S')	s++;
	if(s==0)
	{
		printf("%d",n);
		return 0;
	}
	if(s==1)
	{
		printf("%d",n-1);
		return 0;
	}
	if(s==n)
	{
		printf("0");
		return 0;
	}

	int f=0;
	for(int p=0;p<n;p++)
	{
		if(a[p]=='G')
		{
			f++;
			for(int q=p+1;q<n;q++)
			{
				if(a[q]=='S')
				{
					p=q+1;
					break;
				}
			}
		}
	}

	int sum=0;
	int max=0;
	int flag=0;
	for(int k=0;k<n;k++)
	{
		sum=0;
		if(a[k]=='G')
		{
			for(int j=k;j<n;j++)
			{
				if(a[j]=='G')	sum++;
				if(a[j]=='S')
				{
					k=j;
					break;
				}
			}
			if(sum>max)	max=sum;
		}
	}
	sum=0;
	for(int i=1;i<n-1;i++)
	{

		if(a[i]=='S'&&a[i-1]=='G'&&a[i+1]=='G')
		{
			qian=0;
			for(int q=i-1;q>=0;q--)
			{
				if(a[q]=='G')	qian++;
				if(a[q]=='S')	break;
			}
			hou=0;
			for(int h=i+1;h<n;h++)
			{
				if(a[h]=='G')	hou++;
				if(a[h]=='S')	break;
			}
			sum=qian+hou;
			flag=1;
		}
		if(max<sum)	max=sum;
	}
	if(f==1)					printf("%d",max);
	else if(f==2&&flag==1)		printf("%d",max);
	else if(f==2&&flag==0)		printf("%d",max+1);
	else						printf("%d",max+1);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int n,g[1000]={0},s=1,mark;
    char a;
    cin>>n;
   while(n--)
   {
   	cin>>a;
   	if(a=='G')
   	g[s]++;
   	else
   	{
	 if(g[s]>g[s-1])
	 mark=s;
	 s++;
	}
   }
   s++;
   int f[1000]={0};

   for(int i=0;i<s;i++)
   {
   	f[i]=g[i]+g[i+1]+1;
   	if(i==s-1)
   	f[i]--;
   }
   sort(f,f+s);
   cout<<f[s-1];

}


#include<bits/stdc++.h>
//#define TIME
using namespace std;
typedef long long ll;
const int maxn=100005;
const int inf=0x3f3f3f3f;
inline void read(int &x) {
    int f=1;x=0;char c=getchar();
    while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    x*=f;
}
inline void print(int x) {
	if(x<0){ putchar('-');x=-x;}
	if(x>9) print(x/10);putchar(x%10+'0');
}
int n,m;
bool a[maxn];
int pre[maxn],nxt[maxn];
int main()
{
	int i,j;
	cin>>n;
	getchar();
	for(i=1;i<=n;i++)
	{
		char ch=getchar();
		if(ch=='G') a[i]=1;
		else a[i]=0;
	}
	#ifdef TIME
		clock_t ST=clock();
	#endif
	int tmp=0,cnt=0;
	for(i=1;i<=n+1;i++)
	{
		if(a[i]==1) tmp++;
		if(a[i]==0&&a[i-1]==1)
		{
			cnt++;
			pre[i]=tmp;
			tmp=0;
		}
	}
	tmp=0;
	for(i=n;i>=0;i--)
	{
		if(a[i]==1) tmp++;
		if(a[i]==0&&a[i+1]==1)
		{
			nxt[i]=tmp;
			tmp=0;
		}
	}
	int mx=-1;
	for(i=0;i<=n+1;i++)
	{
		mx=max(mx,pre[i]+nxt[i]);
		if(cnt>=2&&pre[i]==0) mx=max(mx,nxt[i]+1);
		if(cnt>=2&&nxt[i]==0) mx=max(mx,pre[i]+1);
	}
	if(cnt>2) mx++;
	cout<<mx;
	#ifdef TIME
		printf("\n%.2lf ms",double(clock()-ST)/CLOCKS_PER_SEC*1000.0);
	#endif
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char a[100005];
struct jz
{
	int l,r,zhi;
}f[100005];
bool cmp(jz a,jz b)
{
	return a.zhi>b.zhi;
}
int main()
{
	int i,j,k,q;
	int n,maxx;
	scanf("%d",&n);
	getchar();
	for(i=1;i<=n;i++)
		scanf("%c",&a[i]);
	j=1;
	i=1;
	while(a[i]=='S')
			i++;
	while(i<n+1)
	{
		f[j].l=i;
		while(a[i+1]=='G')
			i++;
		f[j].r=i;
		f[j].zhi=f[j].r-f[j].l+1;
		j++;
		i++;
		while(a[i]=='S')
			i++;
	}
	j--;
	if(f[1].l==0) printf("0");
	else
	{
		sort(f+1,f+j,cmp);
		maxx=f[1].zhi;
		for(i=1;i<=j;i++)
			for(k=i+1;k<=j;k++)
			{
				int cj;
				cj=(f[i].l>f[k].r?f[i].l-f[k].r-1:f[k].l-f[i].r-1);
				for(q=1;q<=3;q++)
					if(q!=i&&q!=k)
					{
						if(f[q].zhi>=cj) maxx=max(f[i].zhi+f[k].zhi+cj,maxx);
						break;
					}
			}
		printf("%d",maxx);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char a[100005];
struct jz
{
	int l,r,zhi;
}f[100005];
bool cmp(jz a,jz b)
{
	return a.zhi>b.zhi;
}
int main()
{
	int i,j,k,q;
	int n,maxx;
	scanf("%d",&n);
	getchar();
	for(i=1;i<=n;i++)
		scanf("%c",&a[i]);
	j=1;
	i=1;
	while(a[i]=='S')
			i++;
	while(i<=n)
	{
		f[j].l=i;
		while(a[i+1]=='G')
			i++;
		f[j].r=i;
		f[j].zhi=f[j].r-f[j].l+1;
		j++;
		i++;
		while(a[i]=='S')
			i++;
	}
	j--;
	if(f[1].l==0) printf("0");
	else
	{
		if(j==1)
			printf("%d",f[1].zhi);
		else if(j==2)
		{
			if(f[1].r+2==f[2].l) printf("%d",f[1].zhi+f[2].zhi);
			else printf("%d",max(f[1].zhi,f[2].zhi)+1);
		}
		else
		{
			maxx=0;
			for(i=1;i<j;i++)
				if(f[i].r+2==f[i+1].l)
					maxx=max(maxx,f[i].zhi+f[i+1].zhi+1);
			sort(f+1,f+j+1,cmp);
			maxx=max(maxx,f[1].zhi+1);
			printf("%d",maxx);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rint register int
int n, a[100010], sum[100010], maxn[10010], now, ans;
char ch;
int main( void ){
	scanf( "%d", &n );
	for( rint i = 1; i <= n ; i++ ){
		ch = getchar();
		if( ch == 'G' )	a[i] = 1;
		else a[i] = 0;
		sum[i] = sum[i - 1] + a[i];
		while( sum[i] - sum[now] < i - now - 1 && now <= i ) now++;
		maxn[i] = i - now ;
	}
	for( rint i = 1; i <= n; i++ ){
		if( sum[n] - sum[i] ) ans = max( ans, maxn[i] );
	}
	if( ch == 'G' ) ans++;
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,num,findS,findG;
string s,st;
int main(){
	cin>>n;
	cin>>st;
	s=st;
	for(int i=1;i<=n;i++)
		findS=st.find('S');
	if(findS==string::npos)
		cout<<n;
	if(findS!=string::npos)
	{
		for(int i=n;i>=1;i--)
		{
			if(s[i]=='G'){
				findG=i;
				break;
			}
		}
		if(findG!=0){
			s[findS]='G';
			s[findG]='S';
		}
		for(int i=0;i<n;i++)
		{
			if(s[i]=='G') num++;
			if(s[i]=='S') break;
		}
		cout<<num;
	}
	return 0;
}


#include<bits/stdc++.h>
#define MAX 201000
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n;
char a[MAX];
int dp[MAX],sum[MAX];
int main()
{   ios::sync_with_stdio(false);cin.tie(0);
    int i,j,n;
    cin>>n;
    cin>>a+1;
    for(i=1;i<=n;i++)
    {   if(a[i]=='G')
            dp[i]=dp[i-1]+1;
        else
            dp[i]=0;
    }
    int tmax=0,cnt=1;
    for(i=n;i>=1;i--)
    {   tmax=max(dp[i],tmax);
        if(dp[i]==0)
            tmax=0,cnt++;
        sum[i]=tmax;
    }
    tmax=0;
    if(cnt>1)
    {   for(i=1;i<=n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]+1);
            }
        }
    }
    else
    {   for(i=1;i<=n;i++)
        {   tmax=max(tmax,sum[i]);
        }
    }
    cout<<tmax<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define MAX 201000
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n;
char a[MAX];
int dp[MAX],sum[MAX];
int main()
{   ios::sync_with_stdio(false);cin.tie(0);
    int i,j,n;
    cin>>n;
    cin>>a+1;
    for(i=1;i<=n;i++)
    {   if(a[i]=='G')
            dp[i]=dp[i-1]+1;
        else
            dp[i]=0;
    }
    int tmax=0,cnt=0;
    for(i=n;i>=1;i--)
    {   tmax=max(dp[i],tmax);
        if(dp[i]==0)
            tmax=0;
        sum[i]=tmax;
    }
    int flag=0;
    for(i=1;i<=n;i++)
    {   if(flag==0&&sum[i]>0)
        {   cnt++;flag=1;
        }
        if(sum[i]==0)
            flag=0;
    }
    tmax=0;
    if(cnt>2)
    {   for(i=1;i<=n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]+1);
            }
        }
    }
    else if(cnt==2)
    {   for(i=2;i<n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]);
            }
        }
    }
    else
    {   for(i=1;i<=n;i++)
        {   tmax=max(tmax,sum[i]);
        }
    }
    cout<<tmax<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define MAX 201000
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n;
char a[MAX];
int dp[MAX],sum[MAX];
int main()
{   ios::sync_with_stdio(false);cin.tie(0);
    int i,j,n;
    cin>>n;
    cin>>a+1;
    for(i=1;i<=n;i++)
    {   if(a[i]=='G')
            dp[i]=dp[i-1]+1;
        else
            dp[i]=0;
    }
    int tmax=0,cnt=0;
    for(i=n;i>=1;i--)
    {   tmax=max(dp[i],tmax);
        if(dp[i]==0)
            tmax=0;
        sum[i]=tmax;
    }
    int flag=0;
    for(i=1;i<=n;i++)
    {   if(flag==0&&sum[i]>0)
        {   cnt++;flag=1;
        }
        if(sum[i]==0)
            flag=0;
    }
    tmax=0;
    if(cnt>2)
    {   for(i=1;i<=n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]+1);
            }
        }
    }
    else if(cnt==2)
    {   for(i=1;i<=n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]);
            }
        }
    }
    else
    {   for(i=1;i<=n;i++)
        {   tmax=max(tmax,sum[i]);
        }
    }
    cout<<tmax<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define MAX 201000
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n;
char a[MAX];
int dp[MAX],sum[MAX];
int main()
{   ios::sync_with_stdio(false);cin.tie(0);
    int i,j,n;
    cin>>n;
    cin>>a+1;
    for(i=1;i<=n;i++)
    {   if(a[i]=='G')
            dp[i]=dp[i-1]+1;
        else
            dp[i]=0;
    }
    int tmax=0,cnt=0;
    for(i=n;i>=1;i--)
    {   tmax=max(dp[i],tmax);
        if(dp[i]==0)
            tmax=0;
        sum[i]=tmax;
    }
    tmax=0;
    for(i=2;i<n;i++)
    {   tmax=max(sum[i],tmax);
        if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
        {   tmax=max(tmax,sum[i-1]+sum[i+1]+1);
        }
        else if(sum[i]==0&&sum[i-1]>0)
        {   tmax=max(tmax,sum[i-1]+1);
        }
        else if(sum[i]==0&&sum[i+1]>0)
        {   tmax=max(tmax,sum[i+1]+1);
        }
    }
    cout<<tmax<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define MAX 201000
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n;
char a[MAX];
int dp[MAX],sum[MAX];
int main()
{   ios::sync_with_stdio(false);cin.tie(0);
    int i,j,n;
    cin>>n;
    cin>>a+1;
    for(i=1;i<=n;i++)
    {   if(a[i]=='G')
            dp[i]=dp[i-1]+1;
        else
            dp[i]=0;
    }
    int tmax=-1,cnt=1;
    for(i=n;i>=1;i--)
    {   tmax=max(dp[i],tmax);
        if(dp[i]==0)
            tmax=-1,cnt++;
        sum[i]=tmax;
    }
    tmax=0;
    if(cnt>2)
    {   for(i=1;i<=n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==-1&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]+1);
            }
        }
    }
    else
    {   for(i=1;i<=n;i++)
        {   tmax=max(tmax,sum[i]);
        }
    }
    cout<<tmax<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define MAX 201000
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n;
char a[MAX];
int dp[MAX],sum[MAX];
int main()
{   ios::sync_with_stdio(false);cin.tie(0);
    int i,j,n;
    cin>>n;
    cin>>a+1;
    for(i=1;i<=n;i++)
    {   if(a[i]=='G')
            dp[i]=dp[i-1]+1;
        else
            dp[i]=0;
    }
    int tmax=0,cnt=0;
    for(i=n;i>=1;i--)
    {   tmax=max(dp[i],tmax);
        if(dp[i]==0)
            tmax=0;
        sum[i]=tmax;
    }
    int flag=0;
    for(i=1;i<=n;i++)
    {   if(flag==0&&sum[i]>0)
        {   cnt++;flag=1;
        }
        if(sum[i]==0)
            flag=0;
    }
    tmax=0;
    if(cnt>2)
    {   for(i=1;i<=n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]+1);
            }
        }
    }
    else if(cnt==2)
    {   for(i=2;i<n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]);
            }
            else if(sum[i]==0&&sum[i-1]>0)
            {   tmax=max(tmax,sum[i-1]+1);
            }
            else if(sum[i]==0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i+1]+1);
            }
        }
    }
    else
    {   for(i=1;i<=n;i++)
        {   tmax=max(tmax,sum[i]);
        }
    }
    cout<<tmax<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define MAX 201000
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n;
char a[MAX];
int dp[MAX],sum[MAX];
int main()
{   ios::sync_with_stdio(false);cin.tie(0);
    int i,j,n;
    cin>>n;
    cin>>a+1;
    for(i=1;i<=n;i++)
    {   if(a[i]=='G')
            dp[i]=dp[i-1]+1;
        else
            dp[i]=0;
    }
    int tmax=0,cnt=1;
    for(i=n;i>=1;i--)
    {   tmax=max(dp[i],tmax);
        if(dp[i]==0)
            tmax=0,cnt++;
        sum[i]=tmax;
    }
    tmax=0;
    if(cnt>2)
    {   for(i=1;i<=n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]+1);
            }
        }
    }
    else
    {   for(i=1;i<=n;i++)
        {   tmax=max(tmax,sum[i]);
        }
    }
    cout<<tmax<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define MAX 201000
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n;
char a[MAX];
int dp[MAX],sum[MAX];
int main()
{   ios::sync_with_stdio(false);cin.tie(0);
    int i,j,n;
    cin>>n;
    cin>>a+1;
    for(i=1;i<=n;i++)
    {   if(a[i]=='G')
            dp[i]=dp[i-1]+1;
        else
            dp[i]=0;
    }
    int tmax=0,cnt=1;
    for(i=n;i>=1;i--)
    {   tmax=max(dp[i],tmax);
        if(dp[i]==0)
            tmax=0,cnt++;
        sum[i]=tmax;
    }
    tmax=0;

    for(i=1;i<=n;i++)
    {   tmax=max(sum[i],tmax);
        if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
        {   tmax=max(tmax,sum[i-1]+sum[i+1]+1);
        }
    }

    cout<<tmax<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define MAX 201000
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n;
char a[MAX];
int dp[MAX],sum[MAX];
int main()
{   ios::sync_with_stdio(false);cin.tie(0);
    int i,j,n;
    cin>>n;
    cin>>a+1;
    for(i=1;i<=n;i++)
    {   if(a[i]=='G')
            dp[i]=dp[i-1]+1;
        else
            dp[i]=0;
    }
    int tmax=0,cnt=0;
    for(i=n;i>=1;i--)
    {   tmax=max(dp[i],tmax);
        if(dp[i]==0)
            tmax=0;
        sum[i]=tmax;
    }
    int flag=0;
    for(i=1;i<=n;i++)
    {   if(flag==0&&sum[i]>0)
        {   cnt++;flag=1;
        }
        if(sum[i]==0)
            flag=0;
    }
    tmax=0;
    if(cnt>2)
    {   for(i=1;i<=n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]+1);
            }
            else if(sum[i]==0&&sum[i-1]>0)
            {   tmax=max(tmax,sum[i-1]+1);
            }
            else if(sum[i]==0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i+1]+1);
            }
        }
    }
    else if(cnt==2)
    {   for(i=2;i<n;i++)
        {   tmax=max(sum[i],tmax);
            if(sum[i]==0&&sum[i-1]>0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i-1]+sum[i+1]);
            }
            else if(sum[i]==0&&sum[i-1]>0)
            {   tmax=max(tmax,sum[i-1]+1);
            }
            else if(sum[i]==0&&sum[i+1]>0)
            {   tmax=max(tmax,sum[i+1]+1);
            }
        }
    }
    else
    {   for(i=1;i<=n;i++)
        {   tmax=max(tmax,sum[i]);
        }
    }
    cout<<tmax<<endl;
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

char s[N];

bool IsSilverTrophyPresent(int n){
    for(int i = 0; i < n; ++i){
        if(s[i] == 'S'){
            return 1;
        }
    }
    return 0;
}

int GoldCount(int n){
    int ans = 0;
    for(int i = 0; i < n; ++i){
        ans += (s[i] == 'G');
    }
    return ans;
}

int main(){
    int n;

    scanf("%d%s", &n, s);

    int m = IsSilverTrophyPresent(n);
    int ans = 0;

    for(int i = 0, j = 0, k = 0; i < n; ++i){
        if(s[i] == 'G'){
            for(j = max(j, i); j < n && (k + (s[j] == 'S') <= m); ++j){
                k += (s[j] == 'S');
            }
            ans = max(ans, j - i - (s[j - 1] == 'S'));
        }
        k -= (s[i] == 'S');
        k = max(0, k);
    }

    ans = min(ans, GoldCount(n));

    printf("%d\n", ans);

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

char s[N];

bool IsSilverTrophyPresent(int n){
    for(int i = 0; i < n; ++i){
        if(s[i] == 'S'){
            return 1;
        }
    }
    return 0;
}

int main(){
    int n;

    scanf("%d%s", &n, s);

    int m = IsSilverTrophyPresent(n);
    int ans = 0;

    for(int i = 0, j = 0, k = 0; i < n; ++i){
        for( ; j < n && (k + (s[j] == 'S') <= m); ++j){
            k += (s[j] == 'S');
        }
        ans = max(ans, j - i);
        k -= (s[i] == 'S');
    }

    if(m == 1 && ans == 1){
        ans = 0;
    }

    printf("%d\n", ans);

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

char s[N];

bool IsSilverTrophyPresent(int n){
    for(int i = 0; i < n; ++i){
        if(s[i] == 'S'){
            return 1;
        }
    }
    return 0;
}

int main(){
    int n;

    scanf("%d%s", &n, s);

    int m = IsSilverTrophyPresent(n);
    int ans = 0;

    for(int i = 0, j = 0, k = 0; i < n; ++i){
        if(s[i] == 'G'){
            for(j = max(j, i); j < n && (k + (s[j] == 'S') <= m); ++j){
                k += (s[j] == 'S');
            }
            ans = max(ans, j - i - (s[j - 1] == 'S'));
        }
        k -= (s[i] == 'S');
    }

    printf("%d\n", ans);

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

char s[N];

bool IsSilverTrophyPresent(int n){
    for(int i = 0; i < n; ++i){
        if(s[i] == 'S'){
            return 1;
        }
    }
    return 0;
}

int GoldCount(int n){
    int ans = 0;
    for(int i = 0; i < n; ++i){
        ans += (s[i] == 'G');
    }
    return ans;
}

int main(){
    int n;

    scanf("%d%s", &n, s);

    int m = IsSilverTrophyPresent(n);
    int ans = 0;

    for(int i = 0, j = 0, k = 0; i < n; ++i){
        if(s[i] == 'G'){
            for(j = max(j, i); j < n && (k + (s[j] == 'S') <= m); ++j){
                k += (s[j] == 'S');
            }
            ans = max(ans, j - i);
        }
        k -= (s[i] == 'S');
        k = max(0, k);
    }

    ans = min(ans, GoldCount(n));

    printf("%d\n", ans);

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

char s[N];

bool IsSilverTrophyPresent(int n){
    for(int i = 0; i < n; ++i){
        if(s[i] == 'S'){
            return 1;
        }
    }
    return 0;
}

int main(){
    int n;

    scanf("%d%s", &n, s);

    int m = IsSilverTrophyPresent(n);
    int ans = 0;

    for(int i = 0, j = 0, k = 0; i < n; ++i){
        if(s[i] == 'G'){
            for(j = max(j, i); j < n && (k + (s[j] == 'S') <= m); ++j){
                k += (s[j] == 'S');
            }
            ans = max(ans, j - i - (s[j - 1] == 'S'));
        }
        k -= (s[i] == 'S');
        k = max(0, k);
    }

    printf("%d\n", ans);

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

char s[N];

int GoldCount(int n){
    int ans = 0;
    for(int i = 0; i < n; ++i){
        ans += (s[i] == 'G');
    }
    return ans;
}

int MaxConsecutiveGoldCount(int n){
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'S'){
            continue;
        }
        int ansx = 0;
        for( ; i < n && s[i] == 'G'; ++i){
            ++ansx;
        }
        ans = max(ans, ansx);
    }
    return ans;
}

int main(){
    int n;

    scanf("%d%s", &n, s);

    int m = GoldCount(n), l = MaxConsecutiveGoldCount(n);
    int ans = l + (l != m);

    for(int i = 0; i < n; ++i){
        if(!(s[i] == 'S' && i > 0 && i < n - 1 && s[i - 1] == 'G' && s[i + 1] == 'G')){
            continue;
        }

        int j = i - 1, k = i + 1;
        for( ; j > -1 && s[j] == 'G'; --j);
        for( ; k < n && s[k] == 'G'; ++k);

        int ansx = k - j - 1;
        ans = max(ans, ansx - (ansx > m));
    }

    printf("%d\n", ans);

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

char s[N];

int GoldCount(int n){
    int ans = 0;
    for(int i = 0; i < n; ++i){
        ans += (s[i] == 'G');
    }
    return ans;
}

int MaxConsecutiveGoldCount(int n){
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'S'){
            continue;
        }
        int ansx = 0;
        for( ; i < n && s[i] == 'G'; ++i){
            ++ansx;
        }
        ans = max(ans, ansx);
    }
    return ans;
}

int main(){
    int n;

    scanf("%d%s", &n, s);

    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(!(s[i] == 'S' && i > 0 && i < n - 1 && s[i - 1] == 'G' && s[i + 1] == 'G')){
            continue;
        }

        int j = i - 1, k = i + 1;
        for( ; j > -1 && s[j] == 'G'; --j);
        for( ; k < n && s[k] == 'G'; ++k);

        ans = max(ans, k - j - 1);
    }

    ans = max(ans, MaxConsecutiveGoldCount(n) + (MaxConsecutiveGoldCount(n) != GoldCount(n)));

    printf("%d\n", ans);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int> v[N];
int main() {
	int n,s=0,g=0,cnt=0,ans=0,d=0;
	char c;
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++){
		scanf("%c",&c);
		if(c=='G'){
			if(s>=2) cnt++;
			g++; s=0;
		}
		if(c!='G' || i==n){
			if(g) v[cnt].push_back(g),d++,ans=max(ans,g);
			g = 0; s++;
		}
	}
	if(d<=1) cout<<ans<<endl;
	else{
		for(int i=0;i<=cnt;i++){
			v[i].push_back(0);
			for(int j=0;j<v[i].size()-1;j++){
				if(d>=3) ans = max(ans,v[i][j]+v[i][j+1]+1);
				else ans = max(ans,v[i][j]+v[i][j+1]);
			}
		}
		for(int i=0;i<cnt;i++)
			ans = max(ans,v[i][0]+1);
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int> v[N];
int main() {
	int n,s=0,g=0,cnt=0,ans=0,d=0;
	char c;
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++){
		scanf("%c",&c);
		if(c=='G'){
			if(s>=2) cnt++;
			g++; s=0;
		}
		if(c!='G' || i==n){
			if(g) v[cnt].push_back(g),d++,ans=max(ans,g);
			g = 0; s++;
		}
	}
	if(d<=1) cout<<ans<<endl;
	else{
		v[cnt].push_back(0);
		for(int i=0;i<=cnt;i++){
			for(int j=0;j<v[i].size()-1;j++)
				ans = max(ans,v[i][j]+v[i][j+1]+1);
		}
		if(d==2) ans--;
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int> v[N];
int main() {
	int n,s=0,g=0,cnt=0,ans=0,d=0;
	char c;
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++){
		scanf("%c",&c);
		if(c=='G'){
			if(s>=2) cnt++;
			g++; s=0;
		}
		if(c!='G' || i==n){
			if(g) v[cnt].push_back(g),d++,ans=max(ans,g);
			g = 0; s++;
		}
	}
	if(d<=1) cout<<ans<<endl;
	else{
		for(int i=0;i<=cnt;i++){
			v[i].push_back(0); v[i].push_back(0);
			for(int j=0;j<v[i].size()-1;j++){
				ans = max(ans,v[i][j]+v[i][j+1]);
			}
		}
		if(d>=3) ans++;//���Խ�һ��
		for(int i=0;i<cnt;i++)
			ans = max(ans,v[i][0]+1);
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int> v[N];
int main() {
	int n,s=0,g=0,cnt=0,ans=0,d=0;
	char c;
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++){
		scanf("%c",&c);
		if(c=='G'){
			if(s>=2) cnt++;
			g++; s=0;
		}
		if(c!='G' || i==n){
			if(g) v[cnt].push_back(g),d++,ans=max(ans,g);
			g = 0; s++;
		}
	}
	if(d<=1) cout<<ans<<endl;
	else{
		for(int i=0;i<=cnt;i++){
			v[i].push_back(0);
			for(int j=0;j<v[i].size()-1;j++){
				if(d>=3) ans = max(ans,v[i][j]+v[i][j+1]+1);
				else ans = max(ans,v[i][j]+v[i][j+1])
			}
		}
		for(int i=0;i<cnt;i++)
			ans = max(ans,v[i][0]+1);
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int> v[N];
int main() {
	int n,s=0,g=0,cnt=0,ans=0,d=0;
	char c;
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%c",&c);
		if(c=='G'){
			if(s>=2) cnt++;
			g++; s=0;
		}
		if(c!='G' || i==n){
			if(g) v[cnt].push_back(g),d++,ans=max(ans,g);
			g = 0; s++;
		}
	}
	if(d<=1) cout<<ans<<endl;
	else if(d==2) cout<<ans+1<<endl;
	else{
		v[cnt].push_back(0);
		for(int i=0;i<=cnt;i++){
			for(int j=0;j<v[i].size()-1;j++)
				ans = max(ans,v[i][j]+v[i][j+1]+1);
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int> v[N];
int main() {
	int n,s=0,g=0,cnt=0,ans=0,d=0;
	char c;
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++){
		scanf("%c",&c);
		if(c=='G'){
			if(s>=2) cnt++;
			g++; s=0;
		}
		if(c!='G' || i==n){
			if(g) v[cnt].push_back(g),d++,ans=max(ans,g);
			g = 0; s++;
		}
	}
	if(d<=1) cout<<ans<<endl;
	else if(d==2) cout<<ans+1<<endl;
	else{
		v[cnt].push_back(0);
		for(int i=0;i<=cnt;i++){
			for(int j=0;j<v[i].size()-1;j++)
				ans = max(ans,v[i][j]+v[i][j+1]+1);
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int> v[N];
int main() {
	int n,s=0,g=0,cnt=0,ans=0,d=0;
	string c;
	cin>>n;
	cin>>c;
	for(int i=0;i<n;i++){
		if(c[i]=='G'){
			if(s>=2) cnt++;
			g++; s=0;
		}
		if(c[i]!='G' || i==n-1){
			if(g) v[cnt].push_back(g),d++,ans=max(ans,g);
			g = 0; s++;
		}
	}
	if(d<=1) cout<<ans<<endl;
	else{
		for(int i=0;i<=cnt;i++){
			v[i].push_back(0); v[i].push_back(0);
			for(int j=0;j<v[i].size()-1;j++){
				ans = max(ans,v[i][j]+v[i][j+1]);
			}
		}
		if(d>=3) ans++;//���Խ�һ��
		for(int i=0;i<=cnt;i++)
			ans = max(ans,v[i][0]+1);
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int> v[N];
int main() {
	int n,s=0,g=0,cnt=0,ans=0,d=0;
	char c;
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++){
		scanf("%c",&c);
		if(c=='G'){
			if(s>=2) cnt++;
			g++; s=0;
		}
		if(c!='G' || i==n){
			if(g) v[cnt].push_back(g),d++,ans=max(ans,g);
			g = 0; s++;
		}
	}
	if(d<=1) cout<<ans<<endl;
	else{
		for(int i=0;i<=cnt;i++){
			v[i].push_back(0);
			for(int j=0;j<v[i].size()-1;j++){
				ans = max(ans,v[i][j]+v[i][j+1]);
			}
		}
		if(d>=3) ans++;
		for(int i=0;i<cnt;i++)
			ans = max(ans,v[i][0]+1);
		cout<<ans<<endl;
	}
}


#include <iostream>
#include <string>
#include <vector>
#include <stdint.h>
#include <limits>
#include <algorithm>
#include <math.h>

using namespace std;
#define FOR(I, N) for (int32_t I = 0; I < N; ++I)
#define DRI(A) int32_t A; scanf("%i", &A);
#define DRIII(A, B, C) int32_t A, B, C; scanf("%i %i %i", &A, &B, &C);
//#define INT32_MAX std::numeric_limits<int32_t>::max
#define UP_DIV(A, B) (A + B - 1) / B
int main(int argc, char** argv)
{
    int res = 0;
    int segNum = 0;
    DRI(n);
    std::string s;
    s.reserve(n + 1);
    std::cin >> s;
    s += 'S';

    char* prevStart = nullptr, *prevEnd = nullptr;
    char* start = nullptr;
    char* bestStart = nullptr;
    char* bestEnd = nullptr;
    FOR(i, n + 1)
    {
        if (s[i] == 'G' && !start)
        {
            start = &s[i];
        }

        if (s[i] != 'G' && start)
        {
            int curRes = &s[i] - start;
            bool shouldIncremented = false;
            if (prevEnd && (start - prevEnd == 1))
            {
                curRes += prevEnd - prevStart;
                shouldIncremented = true;
            }
            if (curRes > res)
            {
                bestStart = start;
                bestEnd = &s[i];
            }
            if (curRes == res && shouldIncremented)
            {
                bestStart = start;
                bestEnd = &s[i];
            }

            prevStart = start;
            prevEnd = &s[i];
            res = std::max(res, curRes);
            start = nullptr;
            ++segNum;
        }
    }
    if (segNum > 2 && (bestEnd - bestStart != res))
        ++res;
    if (s == "GGSSGGS")
        std::cout << bestStart << bestEnd << segNum << std::endl;
    std::cout << res;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <stdint.h>
#include <limits>
#include <algorithm>
#include <math.h>

using namespace std;
#define FOR(I, N) for (int32_t I = 0; I < N; ++I)
#define DRI(A) int32_t A; scanf("%i", &A);
#define DRIII(A, B, C) int32_t A, B, C; scanf("%i %i %i", &A, &B, &C);
//#define INT32_MAX std::numeric_limits<int32_t>::max
#define UP_DIV(A, B) (A + B - 1) / B
int main(int argc, char** argv)
{
    int res = 0;
    int gNum = 0;
    DRI(n);
    std::string s;
    s.reserve(n + 1);
    std::cin >> s;
    s += 'S';

    char* prevStart = nullptr, *prevEnd = nullptr;
    char* start = nullptr;
    char* bestStart = nullptr;
    char* bestEnd = nullptr;
    FOR(i, n + 1)
    {
        if (s[i] == 'G')
            ++gNum;
        if (s[i] == 'G' && !start)
        {
            start = &s[i];
        }

        if (s[i] != 'G' && start)
        {
            int curRes = &s[i] - start;
            bool shouldIncremented = false;
            if (prevEnd && (start - prevEnd == 1))
            {
                curRes += prevEnd - prevStart;
                shouldIncremented = true;
            }
            if (curRes > res)
            {
                bestStart = start;
                bestEnd = &s[i];
            }
            if (curRes == res && shouldIncremented)
            {
                bestStart = start;
                bestEnd = &s[i];
            }

            prevStart = start;
            prevEnd = &s[i];
            res = std::max(res, curRes);
            start = nullptr;
        }
    }
    if (gNum > res && (bestEnd - bestStart != res))
        ++res;
    std::cout << res;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <stdint.h>
#include <limits>
#include <algorithm>
#include <math.h>

using namespace std;
#define FOR(I, N) for (int32_t I = 0; I < N; ++I)
#define DRI(A) int32_t A; scanf("%i", &A);
#define DRIII(A, B, C) int32_t A, B, C; scanf("%i %i %i", &A, &B, &C);
//#define INT32_MAX std::numeric_limits<int32_t>::max
#define UP_DIV(A, B) (A + B - 1) / B
int main(int argc, char** argv)
{
    int res = 0;
    int segNum = 0;
    DRI(n);
    std::string s;
    std::cin >> s;

    char* prevStart = nullptr, *prevEnd = nullptr;
    char* start = nullptr;
    FOR(i, n + 1)
    {
        if (s[i] == 'G' && !start)
        {
            start = &s[i];
        }

        if (s[i] != 'G' && start)
        {
            int curRes = &s[i] - start;
            if (prevEnd && (start - prevEnd == 1))
                curRes += prevEnd - prevStart;
            prevStart = start;
            prevEnd = &s[i];
            res = std::max(res, curRes);
            start = nullptr;
            ++segNum;
        }
    }
    if (segNum > 2)
        ++res;
    std::cout << res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)

int main(){
	int n;sd(n);
	int x=1000000000,y=1;
	int a[n];
	int last=-1;
	int flag=0;
	int present;
	sd(last);
	y=last;
	a[0]=last;
	for(int i=1;i<n;i++)
		{
			sd(present);
			a[i]=present;
			if(present-last>1){
				if(flag==1){
					if(present-last!=y)
					{
						cout<<"NO";return 0;
					}
				}
				else
				{
					y=present-last;
					flag=1;
				}
			}
			else if(last-present>1){
				if(flag==1){
					if(last-present!=y)
					{
						cout<<"NO";return 0;
					}
				}
				else
				{
					y=last-present;
					flag=1;
				}
			}
			else{

			 if(abs(last-present)==1)
				{
					if(last>present){
						if(flag==1)
						 if((last-1)%y <(present-1)%y)
						{
							cout<<"NO";return 0;
						}

					}
					else
					{
							if(flag==1)
					 if((last-1)%y >(present-1)%y)
						{
							cout<<"NO";return 0;
						}
						if(flag==0)
							y++;

					}
				}
			}
			last=present;
		}
		last=a[0];
		for(int i=1;i<n;i++)
		{

			present=a[i];
			if(present-last>1){
					if(present-last!=y)
					{
						cout<<"NO";return 0;
					}

			}
			else if(last-present>1){
					if(last-present!=y)
					{
						cout<<"NO";return 0;
					}

			}
			else{
				if(last==present)
						{
							cout<<"NO";return 0;
						}

			 if(abs(last-present)==1)
				{
					if(last>present){
						 if((last-1)%y <(present-1)%y)
						{
							cout<<"NO";return 0;
						}

					}
					else
					{
					 if((last-1)%y >(present-1)%y)
						{
							cout<<"NO";return 0;
						}
					}
				}
			}
			last=present;
		}
	cout<<"YES"<<endl;

	cout<<x<<" "<<y<<endl;
}


#include <bits/stdc++.h>
using namespace std ;
#define max 1000000000

long long solve( vector <int> &v, int n )
{
    long long y = -1 ;
    int i = 0 ;

    while( i < ( n -1) )
    {
        long long dist = abs(v[i]-v[i+1]) ;

        if( dist != 1 )
        {
            if( y == -1 )
            {
                y = dist ;
            }

            else
            {
                if( dist != y )
                    return -1 ;
            }
        }
        i++ ;
    }

    if( y == -1 )
        return 1 ;
    if( !y )
        return 0 ;

     i = 0;
     int cy1, cy2 ;

    while( i < ( n ) )
    {
        if( v[i] % y == 0 )
        {
            if( i )
            {
                if( v[i-1] == v[i]+1)
                    return -1 ;
            }

            if( i < (n-1))
            {
                if( v[i+1] == v[i]+1 )
                    return -1 ;
            }
        }
        i++ ;
    }

    return y ;
}

int main()
{
    int n ;
    cin >> n ;
    vector <int> v(n) ;

    for( int i = 0 ; i < n ; i++ )
    {
        cin >> v[i] ;
    }

    long long y = solve( v, n ) ;

    if( y == -1 )
        cout<<"NO\n" ;

    else if(!y)
    {
        cout<<"NO\n" ;
    }
    else if( y == 1 )
    {
        cout<<"YES\n" ;
        cout<<max<<" "<<1<<"\n" ;
    }

    else
    {
        long long z, x ;
        z = *max_element( v.begin(), v.end()) ;

        if( z % y )
            x = (z/y) + 1 ;
        else
            x = z/y ;

        if( (x) > max )
            cout<<"NO\n" ;

        else
        {
            cout<<"YES\n" ;
            cout<<x<<" "<<y<<"\n" ;
        }
    }

    return 0 ;
}


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define PI 3.1415926535897932384626433832
#define MOD 1000000007
#define MOD2 1000000009
#define bas 29
#define bas2 19
using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int res = n;
    for(int i = 1; i <= n/2; i++){
        if(s.substr(0, i) == s.substr(i, i)){
            res = min(res, i + 1 + n - ( 2 * i));
        }
    }

    cout << res;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef vector<pii> vii;
typedef vector<vector<pii> > vvii;
typedef long double ld;
typedef map<int, int> mapii;
typedef map<string, int> mapsi;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pi  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-8)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'
#define output freopen("output.txt", "w", stdout)
#define mp(x, y, z) {x, {y, z}}

ll x, y;

bool valid(ll i)
{
	return (i >= 1 && i <= x*y);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	x = 1e9, y = 1e9;
	vi vec(n);
	rep(i, 0, n)
	{
		cin >> vec[i];

		if (i)
		{
			if (vec[i] == vec[i-1])
				y = 0;
			int diff = abs(vec[i] - vec[i-1]);

			if (y == 1e9 && diff != 1)
				y = diff;
		}
	}

	if (!y)
		return cout << "NO", 0;

	rep(i, 1, n)
	{
		int a = vec[i-1], b = vec[i];
		int diff = abs(a-b);
		if (diff == 1 || diff == y)
		{
			if (valid(a) && valid(b))
			{

			}
			else
				return cout << "NO", 0;
		}
		else
			return cout << "NO", 0;

		if (diff == 1)
		{
			if (a < b)
			{
				if (a%y == 0 && b%y == 1)
					return cout << "NO", 0;
			}
			else
			{
				if (a%y == 1 && b%y == 0)
					return cout << "NO", 0;
			}
		}
	}

	cout << "YES\n";
	cout << x << " " << y << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define mod 1000000007
#define all(a) a.begin(), a.end()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

#define FOR (i, a, b) for(int i = a; i <  b; i++)
#define FORN(i, a, b) for(int i = a; i <= b; i++)
#define fORN(i, b, a) for(int i = b; i >= a; i--)
#define _1 first
#define _2 second

const double EPS = 1e-9;
const double PI = acos(-1.);
const int MOD = 1e9 + 7;
const int MAX = 1e-9;

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;

    return true;
}

void input(int *a, int size)
{
    for(int i = 0; i < size; ++i) {
        cin >> a[i];
    }
}

void output(int *a, int size)
{
    for(int i = 0; i < size; ++i) {
        cout << a[i] << " ";
    }
    cout<<endl;
}
int n, jump = 1e9, d = 1e9;
int A[200001];
__INT16_C() main()
{
    cin >> n;
    input(A, n);
    for(int i = 1; i < n; i++) {
        if(abs(A[i] - A[i - 1]) > 1) {
            jump = min(jump, abs(A[i] - A[i - 1]));
        }
    }
    for(int i = 1; i < n; i++) {
        if(A[i] == A[i - 1])
        return cout << "NO",0;
        if(abs(A[i] - A[i - 1]) == 1 && ceil(1.* A[i - 1] / jump)!= ceil(1.* A[i] / jump)) {
            return cout << "NO",0;
        }
        if(abs(A[i] - A[i - 1]) > 1 && abs(A[i] - A[i - 1]) != jump)
            return cout << "NO",0;
    }
    cout << "YES" << endl;
    cout << d << " " << jump;

}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	scanf("%d", &n);
	vector<int> v(n);
	int R = 1, C = 1e9;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &v[i]);
		--v[i];
		if (i) {
			if (abs(v[i] - v[i - 1]) > 1) {
				R = 1e9;
				C = abs(v[i] - v[i - 1]);
			}
		}
	}
	ll r = v[0] / C, c = v[0] % C;
	if (r >= R) {
		puts("NO");
		return 0;
	}
	for (int i = 1; i < n; ++i) {
		ll xr = v[i] / C;
		ll xc = v[i] % C;
		if (xr >= R || abs(xr - r) + abs(xc - c) != 1) {
			puts("NO");
			return 0;
		}
		r = xr;
		c = xc;
	}
	puts("YES");
	printf("%d %d\n", R, C);
	return 0;
}


/*
Author: CNYALI_LK
LANG: C++
PROG: c.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<int,int> pii;
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
int read(){
	int s=0,base=1;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=-base;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	return s*base;
}
char WriteIntBuffer[1024];
template<class T>void write(T a,char end){
	int cnt=0,fu=1;
	if(a<0){putchar('-');fu=-1;}
	do{WriteIntBuffer[++cnt]=fu*(a%10)+'0';a/=10;}while(a);
	while(cnt){putchar(WriteIntBuffer[cnt]);--cnt;}
	putchar(end);
}
int a[292608];
int main(){
#ifdef cnyali_lk
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
#endif
	int n;
	n=read();
	for(int i=1;i<=n;++i)a[i]=read();

	if(n==1)printf("YES\n1 %d\n",a[1]);
	else{
		int yes=1;
		for(int i=1;i<n;++i)
			if(a[i]==a[i+1])yes=0;
		if(!yes)printf("NO\n");
		else{
			int is=1;
			for(int i=1;i<n;++i){
				if(abs(a[i]-a[i+1])!=1)is=0;
			}
			if(is){
				int ans=0;
				for(int i=1;i<=n;++i)chkmax(ans,a[i]);
				printf("YES\n1 %d\n",ans);
			}
			else{
				for(int i=1;i<=n;++i)--a[i];
				int equ=0;
				for(int i=1;i<n;++i)if(abs(a[i]-a[i+1])!=1){
					if(!equ)equ=abs(a[i]-a[i+1]);
					else if(equ!=abs(a[i]-a[i+1]))yes=0;
				}
				if(yes){
					for(int i=1;i<n;++i)if(abs(a[i]-a[i+1])==1)if(a[i]/equ!=a[i+1]/equ)yes=0;
					if(yes){
						printf("YES\n");
						int ans=0;
						for(int i=1;i<=n;++i)chkmax(ans,a[i]/equ+1);
						printf("%d %d\n",ans,equ);
					}
					else printf("NO\n");
				}
				else printf("NO\n");
			}
		}
	}
	return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

#define MAX_N 200000

void no(int ex = -1) {
	cout << "NO\n";
	exit(0);
}

int numbers[MAX_N];
pair<int, int> coords[MAX_N];
int maxY(0), minY(0);
int minX(0), maxX(0);
int xPromise(-1);

#define x first
#define y second

bool check(pair<int, int> a, pair<int, int> b) {
	if(a.x == b.x && fabs(a.y - b.y) == 1)
		return true;
	if(a.y == b.y && fabs(a.x - b.x) == 1)
		return true;
	return false;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	for(int i(0); i < n; ++i)
		cin >> numbers[i];
	int x(0), y(0);
	if(numbers[0] < 1)	no();
	for(int i(1); i < n; ++i) {
		if(numbers[i] - numbers[i - 1] == 1)
			++y;
		if(numbers[i] - numbers[i - 1] == -1)
			--y;
		if(numbers[i] - numbers[i - 1] > 1) {
			++x;
			if(xPromise < 0)
				xPromise = numbers[i] - numbers[i - 1];
			if(xPromise != numbers[i] - numbers[i - 1])	no();
		}
		if(numbers[i] - numbers[i - 1] < -1) {
			--x;
			if(xPromise < 0)
				xPromise = numbers[i - 1] - numbers[i];
			if(xPromise != numbers[i - 1] - numbers[i])	no();
		}
		if(numbers[i] < 1)	no();
		if(numbers[i] == numbers[i - 1])	no();
		maxX = max(maxX, x);
		maxY = max(maxY, y);
		minX = min(minX, x);
		minY = min(minY, y);
	}

	if(xPromise < 0)
		xPromise = 1000000000;
	if(maxY - minY + 1 > xPromise)	no();

	coords[0] = {(numbers[0] - 1) / xPromise, (numbers[0] - 1) % xPromise};
	for(int i(1); i < n; ++i) {
		coords[i] = {(numbers[i] - 1) / xPromise, (numbers[i] - 1) % xPromise};
		if(!check(coords[i - 1], coords[i]))	no();
	}
	cout << "YES\n";
	cout << 1000000000 << " " << xPromise << endl;
	return 0;
}


// ReSharper disable once CppInconsistentNaming
#define _CRT_SECURE_NO_WARNINGS
#include <utility>
#include <list>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <numeric>
#include <stack>
#include <bitset>
#include <queue>
#include <cctype>
#include <unordered_set>
#include <map>
#include <fstream>
#include <iterator>
#include <vector>
#include <regex>
#include <deque>
#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;

	if (n == 1)
	{
		int k;
		cin >> k;
		cout << "YES" << endl;
		cout << 1 << " " << k;
		return false;
	}

	vector<int> a(n, 0);

	int diff = 1;
	cin >> a[0];
	int mx = a[0];

	for (int i = 1; i < n; ++i)
	{
		cin >> a[i];

		if (a[i] == a[i - 1]) {

			cout << "NO";
			return false;
		}

		mx = max(a[i], mx);

		int diff2 = abs(a[i] - a[i - 1]);
		if (diff == 1)
		{
			diff = max(diff, diff2);
		}
		else if (diff2 != 1 && diff != diff2)
		{
			cout << "NO";
			return false;
		}
	}

	if (diff == 1)
	{
		cout << "YES" << endl;
		cout << 1 << " " << mx;
		return false;
	}

	int y = diff;
	int x = mx % y == 0 ? mx / y : mx / y + 1;

	if (x == 1)
	{
		cout << "YES" << endl;
		cout << x << " " << y;
		return false;
	}

	for (int i = 1; i < n; ++i)
	{
		if (abs(a[i] - a[i - 1]) != 1)
		{
			continue;
		}

		if (a[i] > a[i - 1])
		{
			if (a[i - 1] % y == 0)
			{
				cout << "NO";
				return false;
			}
		}
		else if (a[i] < a[i - 1])
		{
			if (a[i - 1] % y == 1)
			{
				cout << "NO";
				return false;
			}
		}
	}

	cout << "YES" << endl;
	cout << x << " " << y;

	return false;
}


//In the name of God
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define ll long long
#define acm ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define mod 1000000007
#define EPS 1e-9
using namespace std;
vector<ll>v;
int main()
{
    acm;
    ll n,ans=LLONG_MIN;
    cin>>n;
    for (int i=0; i<n; ++i)
    {
        ll a;
        cin>>a;
        ans=max(ans,abs(a));
        v.pb(a);
    }
    ll mx=0;
    for (int i=1; i<n; ++i)
    {
        if (v[i]==v[i-1]) return cout<<"NO\n",0;
        mx=max(mx,abs(v[i]-v[i-1]));

    }
    if (mx==0) return cout<<"YES\n"<<abs(v.back())<<" "<<abs(v.back())<<"\n",0;
    for (int i=1; i<n; ++i)
    {
        if (v[i]>v[i-1])
        {
            if (mx==1)
            {
                if (abs(v[i]-v[i-1])!=1) return cout<<"NO\n",0;
            }
            else
            {
                if (abs(v[i]-v[i-1])==1)
                {
                    if (((v[i-1]-1)%mx)+1!=((v[i]-1)%mx))
                        return cout<<"NO\n",0;
                }
                else
                {
                    if (abs(v[i]-v[i-1])!=mx)
                        return cout<<"NO\n",0;
                }
            }
        }
        else
        {
            if (mx==1)
            {
                if (abs(v[i]-v[i-1])!=1) return cout<<"NO\n",0;
            }
            else
            {
                if (abs(v[i]-v[i-1])==1)
                {
                    if (((v[i-1]-1)%mx)!=((v[i]-1)%mx)+1)
                        return cout<<"NO\n",0;
                }
                else
                {
                    if (abs(v[i]-v[i-1])!=mx)
                        return cout<<"NO\n",0;
                }
            }
        }
    }
    if (mx==1) return cout<<"YES\n"<<1<<" "<<ans<<"\n",0;
    cout<<"YES\n"<<mx<<" "<<mx<<"\n";
    return 0;
}


#include <bits/stdc++.h>
#define re return
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i)
        cin >> a[i];
    set<int> st;
    for(int i=1;i<n;++i){
        if(abs(a[i]-a[i-1])<=1)continue;
        st.insert(abs(a[i]-a[i-1]));
    }
    if(st.size()==0){
        cout<<"YES\n1 ";
        sort(a.begin(),a.end());
        cout<<a.back()<<endl;
        re 0;
    }
    if(st.size()==1)
        cout<<"YES\n"<<*st.begin()<<" "<<*st.begin()<<endl;
    else cout<<"NO\n";
    re 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector <int> p(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];
    set <int> st;
    for (int i = 0; i < n - 1; i++)
    {
        if (p[i + 1] == p[i])
        {
            cout << "NO";
            return 0;
        }
        if (p[i + 1] > p[i])
            if (p[i + 1] - p[i] > 1)
                st.insert(p[i + 1] - p[i]);
            else
                ;
        else
            if (p[i] - p[i + 1] > 1)
                st.insert(p[i] - p[i + 1]);
            else
                ;
    }

    if (st.size() > 1)
        cout << "NO";
    else
        if (st.size() == 0)
        {
            sort(p.begin(), p.end());
            cout << "YES" << endl << 1 << ' ' << p[n - 1];
        }
        else
        {
            bool b = true;
            int jj = *st.begin();
            for (int i = 0; i < n - 1; i++)
                if (p[i + 1] > p[i] && p[i + 1] - p[i] == 1)
                    if (p[i] % jj == 0)
                    {
                        b = false;
                        break;
                    }
                    else
                        ;
                else
                    if (p[i + 1] < p[i] && p[i] - p[i + 1] == 1)
                        if (p[i] % jj == 1)
                        {
                            b = false;
                            break;
                        }
                    else
                        ;
            if (!b)
                cout << "NO";
            else
            {
                int x;
                sort(p.begin(), p.end());
                if (p[n - 1] % jj == 0)
                    x = p[n - 1] / jj;
                else
                    x = p[n - 1] / jj + 1;
                cout << "YES" << endl << x << ' ' << jj;
            }
        }
}


#include <bits/stdc++.h>
#define re return
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i)
        cin >> a[i];
    set<int> st;
    for(int i=1;i<n;++i){
        if(a[i]==a[i-1])exit(puts("NO"));
        if(abs(a[i]-a[i-1])==1)continue;
        st.insert(abs(a[i]-a[i-1]));
    }
    if(st.size()==1){
        int hna=*st.begin();
        for(int i=0;i<n-1;++i){
            if(a[i]%hna==0&&a[i+1]%hna==1)exit(puts("NO"));
            if(a[i+1]%hna==0&&a[i]%hna==1)exit(puts("NO"));
        }
        cout<<"YES\n"<<hna<<" "<<hna<<endl;
    }
    else cout<<"NO\n";
    re 0;
}


#include <bits/stdc++.h>
#define re return
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i)
        cin >> a[i];
    set<int> st;
    for(int i=1;i<n;++i){
        if(a[i]==a[i-1])exit(puts("NO"));
        if(abs(a[i]-a[i-1])==1)continue;
        st.insert(abs(a[i]-a[i-1]));
    }
    if(st.size()==0){
        cout<<"YES\n1 ";
        sort(a.begin(),a.end());
        cout<<a.back()<<endl;
        re 0;
    }
    if(st.size()==1){
        int hna=*st.begin();
        for(int i=0;i<n-1;++i){
            if(a[i]%hna==0&&a[i+1]%hna==1)exit(puts("NO"));
            if(a[i+1]%hna==0&&a[i]%hna==1)exit(puts("NO"));
        }
        cout<<"YES\n"<<hna<<" "<<hna<<endl;
    }
    else cout<<"NO\n";
    re 0;
}


#include <bits/stdc++.h>
#define fo(i, u, v) for(int i = u; i <= v; ++i)
#define fob(i, u, v) for(int i = u; i >= v; --i)
#define fi first
#define se second
#define si size()
#define pb push_back

using namespace std;
typedef double db;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll N = 5*1e5+7;
const ll inf = ll(1e18);
const ll  MOD = 1e9+7;
const string name = "in";
template <class T> int getbit(T x, int y) {return x >> (y-1) & 1;}
template <class T> T sqr(T x) {return x*x;}
template <class T> void read_int(T &rs) {
    char c;
    int sign = 1;
    for(c = getchar(); c < '0' || c > '9'; c = getchar())
        if(c == '-') sign *= -1;
    rs = (c - '0');
    for(c = getchar(); c >= '0' && c <= '9'; c = getchar())
        rs = rs*10 + (c - '0');
    rs *= sign;
}

ll a[N], n, x, y;

bool check(ll u, ll v) {
    ll xu, yu, xv, yv;
    xu = u / y + 1; yu = u % y + 1;
    xv = v / y + 1; yv = v % y + 1;
    if(xu < 1 || xu > x || yu < 1 || yu > y) return false;
    if(xv < 1 || xv > x || yv < 1 || yv > y) return false;
    if(abs(xu - xv) + abs(yv - yu) != 1) return false;
    return true;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen((name + ".inp").c_str(), "r", stdin);
    //freopen((name + ".out").c_str(), "w", stdout);
    cin >> n;
    fo(i, 1, n) {
        cin >> a[i];
        if(abs(a[i] - a[i-1]) > 1 && i > 1) {
            if(y == 0) y = abs(a[i] - a[i-1]);
            else if(y != abs(a[i] - a[i-1])) {cout << "NO"; return 0;}
        }
        x = max(x, a[i]);
        if(i > 1 && a[i] == a[i-1]) {cout << "NO"; return 0;}
    }
    if(y == 0) {cout << "YES\n"; cout << 1 << ' ' << x; return 0;}
    x = x / y + bool (x % y);
    fo(i, 1, n-1) if(!check(a[i] - 1, a[i+1] - 1)) {cout << "NO"; return 0;}
    cout << "YES\n"; cout << x << ' ' << y;
    return 0;
}