#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

struct info{
    int l, r, cnt;
    info(int l, int r, int cnt):l(l),r(r),cnt(cnt){}
    info(){}
};

signed main(){
    
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    a.push_back(-1);
    vector<info> v;

    int l = 0;
    for(int r = 1; r <= n; r++){
        if(a[r] == a[r - 1] || a[r] == -1){
            v.push_back(info(a[l], a[r - 1], r - l));
            //cout << a[l] << " " << a[r - 1] << " " << r - l << endl;
            l = r;
        }
    }

    int ans = 0;
    for(int i = 0; i < (int)v.size(); i++){
        if(i == 0 && i == (int)v.size() - 1) ans = v[i].cnt;
        else if(i == 0) ans = max(ans, v[i].cnt + v[i + 1].cnt);
        else if(i == (int)v.size() - 1) ans = max(ans, v[i].cnt + v[i - 1].cnt);
        else ans = max(ans, v[i].cnt + v[i + 1].cnt + v[i - 1].cnt);
    }

    cout << ans << endl;

    return 0;
}
