#include "bits/stdc++.h"
using namespace std;

//#define rep(i, n)     for(auto i = 0; i != n; ++i)
#define REP(i, k, n)  for(auto i = k; i != n; ++i)
//#define rrep(i, n)    for(auto i = n; i != 0; --i)
#define RREP(i, n, k) for(auto i = n; i != k; --i)

#define debug(x) cerr << #x << " " << x << endl
#define spc << " " <<

#define mp make_pair
#define mt make_tuple

using ll = long long;
using Pii = pair<int, int>;
using Tiii = tuple<int, int, int>;
template<typename T>using V = vector<T>;
using Vi = vector<int>;
using VVi = vector<vector<int>>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    Vi seq_len;
    int N; cin >> N;

    int last; cin >> last;
    int streak = 1;
    REP(i, 2, N+1) {
        int light; cin >> light;
        if (light != last) ++streak;
        else {
            seq_len.push_back(streak);
            streak = 1;
        }
        last = light;
    }

    seq_len.push_back(streak);
    seq_len.insert(seq_len.begin(), 0);
//    REP(i,0,seq_len.size()) cout << seq_len[i] << " "; cout << endl;

    REP(i, 1, seq_len.size()) {
        seq_len[i] += seq_len[i-1];
    }

    int ans = 0;
    if (seq_len.size() > 3) {
        REP(i, 3, seq_len.size()) {
            ans = max(ans, seq_len[i] - seq_len[i-3]);
        }
    } else {
        ans = seq_len[seq_len.size()-1];
    }

    cout << ans << endl;
//    REP(i,0,seq_len.size()) cout << seq_len[i] << " "; cout << endl;

    return 0;
}

