#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  int a[100000];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];

  vector<int> vec;
  for(int i = 0; i < n; i++){
    int cnt = 1;
    while(a[i] != a[i + 1] && i != n - 1){
      cnt++;
      i++;
    }
    vec.push_back(cnt);
  }

  int ans = 0;
  if(vec.size() <= 2) ans = n;
  else{
    for(int i = 0; i < vec.size() - 2; i++){
      if(vec[i] + vec[i + 1] + vec[i + 2] > ans) ans = vec[i] + vec[i + 1] + vec[i + 2];
    }
  }

  cout << ans << endl;
  return 0;
}