#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> Q;

int main() {
	int n;
	cin >> n;
	int a, b, c, d;
	c = 1;
	cin >> a;
	d = a;
	b = a;
	vector<Q> q;
	for (int i = 1; i < n; i++) {
		cin >> a;
		if (a == b) {
			P p = P(d, a);
			q.push_back(Q(c, p));
			d = a;
			c = 1;
		} else {
			c++;
			b = a;
		}
	}
	if (c != 0) {
		q.push_back(Q(c, P(d, a)));
	}
	int MAX = q[0].first;
	int sz = q.size();
	/*for (int i = 0; i < sz; i++) {
		cout << q[i].first << ' ' << (q[i].second).first << ' ' << (q[i].second).second << endl;
	}*/
	for (int i = 0; i < sz; i++) {
		if (i+1 < sz) {
			MAX = max(MAX, q[i].first+q[i+1].first);
		}
		if (i+2 < sz) {
			if (((q[i].second).second == (q[i+1].second).first) && ((q[i+1].second).second == (q[i+2].second).first)) {
				MAX = max(MAX, q[i].first+q[i+1].first+q[i+2].first);
			}
		}
	}
	cout << MAX << endl;
	return 0;
}