#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,t,m=0,k=1;
    cin>>n;
    vector<int>v;
    vector<int>l(n,1);
    for(int i=0;i<n;i++){
        cin>>t;
        v.push_back(t);
    }
    for(int i=1;i<n;i++){
        if(v[i-1]!=v[i]){
            l[i]=l[i-1]+1;
        }
    }
    for(int i=n-2;i>=0;i--){
        m=max(m,k+l[i]+(i-l[i]<0?0:l[i-l[i]]));
        k=v[i]==v[i+1]?1:k+1;
    }
    cout<<m<<endl;
}