#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX_N=100000;

int N;
int ill[MAX_N];

int line[MAX_N],line2[MAX_N];

int main(){
	scanf("%d",&N);
	int i;
	for (i=0;i<N;i++){
		scanf("%d",ill+i);
	}
	int ma=1;
	line[0]=1;
	for (i=1;i<N;i++){
		if (ill[i-1]!=ill[i]){
			line[i]=line[i-1]+1;
			ma=max(ma,line[i]);
		}
		else{
			line[i]=1;
		}
	}
	line2[N-1]=1;
	for (i=N-2;i>=0;i--){
		if (ill[i+1]!=ill[i]){
			line2[i]=line2[i+1]+1;
		}
		else{
			line2[i]=1;
		}
	}
	int s=0,t=0;
	while (s<N){
		//s,tを大きくしていく
		while (t<N-1 && ill[t]!=ill[t+1]){
			t++;
		}
		ma=max(ma,t-s+1+(s>0 ? line[s-1] : 0)+(t<N-1 ? line2[t+1] : 0));
		s=t+1;
		t=s;
	}
	printf("%d\n",ma);
	return 0;
}