
#include <bits/stdc++.h>

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) a.begin(),a.end()
#define fst first
#define scd second

signed main()
{
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	
	vector<int> b;
	
	b.push_back(0);
	b.push_back(1);
	
	for(int i=1;i<n;++i) {
		if (a[i]!=a[i-1])b[b.size()-1]++;
		else b.push_back(1);
	}
	
	b.push_back(0);
	
	//rep(i, b.size()) printf("b[%d] = %d\n", i, b[i]);
	
	int ans = 0;
	
	for (int i = 2; i < b.size(); ++i) {
		ans = max(ans, b[i-2]+b[i-1]+b[i]);
	}
	
	cout << ans << endl;
}