#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, a[100009];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	vector<int> z;
	int p = 0;
	for (int i = 1; i <= n; i++) {
		if (i == n || a[i - 1] == a[i]) {
			z.push_back(i - p);
			p = i;
		}
	}
	int ret = (z.size() <= 3 ? n : 0);
	for (int i = 3; i <= z.size(); i++) {
		ret = max(ret, z[i - 3] + z[i - 2] + z[i - 1]);
	}
	printf("%d\n", ret);
	return 0;
}