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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main() {
  int N;
  vector<int> v;

  cin >> N;
  int pre = -1;
  Rep(i, N) {
    int a; cin >> a;
    if ( pre == a ) v.pb(i);
    pre = a;
  }
  v.pb(N);
  //Rep(i, v.size()) cout << v[i] << endl;

  int a = 0, b = 0, c = 0, d = 0;;
  int ans = 0;
  Rep(i, v.size()) {
    a = v[i];
    ans = max(ans, (a-b)+(b-c)+(c-d));
    d = c; c = b; b = a;
  }

  cout << ans << endl;
}