#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int N;

int main() {
  cin >> N;
  bool h;
  int t = 0;
  int a = 0, b = 0, c = 0;
  int ans = 0;
  for (int i=0; i<=N; i++) {
    int x;
    if (i == N) x = h^1;
    else {
      cin >> x;
      if (i & 1) x ^= 1;
    }
    if (i == 0) h = x ^ 1;
    if (x != h) {
      a = b, b = c, c = t;
      ans = max(ans, a+b+c);
      t = 1, h = x;
    }
    else {
      t++;
    }
  }
  cout << ans << "\n";
  return 0;
}