#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> v;
  int d[N]; FOR(i,0,N) cin >> d[i];
  int cnt = 1;
  FOR(i,0,N-1) {
    if(d[i] != d[i+1]) cnt++;
    else {
      v.push_back(cnt);
      cnt = 1;
    }
  }
  v.push_back(cnt);
  if(v.size() == 1) cout << v[0] << endl;
  else if(v.size() == 2) cout << v[0] + v[1] << endl;
  else {
    int ans = 0;
    FOR(i,0,v.size()-2) ans = max(ans, v[i]+v[i+1]+v[i+2]);
    cout << ans << endl;
  }
  return 0;
}