Problem:
電飾(Illumination)
JOI 高校の文化祭では毎年廊下に電飾が飾られる．電飾は
N
個の電球で構成されており，電球は廊下の西側から東側に一列に並んでいる．各電球は明かりがついているか，ついていないかのいずれかの状態である．
JOI 高校の倉庫には電球を操作する機械が眠っている．この機械は電飾内で連続した電球を指定すると，指定された電球のうち，明かりがついている電球全てを明かりがついていない状態にし，明かりがついていない電球全てを明かりがついている状態にする．ただし，機械は老朽化のため，1 回しか使用できない．
JOI 高校の生徒達は明かりがついている電球とついていない電球が交互に並んだ列（このような電球の列を交互列と呼ぶ）が好きである．そこで，この機械を必要ならば1 回だけ使って，できるだけ長い交互列を含む電飾を作ることにした．
例
例えば，電飾の配置が西から東に向かって
となっていたとする（○は明かりがついている電球を，●は明かりがついていない電球を表す）．このとき，4 番目から7 番目までの4 個の電球に対して機械を操作すると，
となり，2 番目から8 番目までの電球が長さ7 の交互列をなす．
また，8 番目の電球のみに対して機械を操作すると，
となり，4 番目から10 番目までの電球が長さ7 の交互列をなす．
機械を最大1 回使用することで，長さが8 以上の交互列を作ることはできない．
課題
電飾の情報が与えられたとき，機械を最大1 回使用することで得られる電球の配列に含まれる交互列の長さとして考えられるものの最大値を求めるプログラムを作成せよ．
制限
2 ≤
N
≤ 100 000      電飾を構成する電球の個数
入力
標準入力から以下のデータを読み込め．
1 行目には整数
N
が書かれている．
2 行目には
N
個の 0 または 1 が空白を区切りとして書かれている．各整数は機械を操作する前における電球の情報を表している．左から
i
( 1 ≤
i
≤
N
) 番目の整数は西側から
i
番目の電球の情報を表しており，整数が 1 ならば電球の明かりがついていて，0 ならば明かりがついていないことを表す．
出力
標準出力に，作成可能な電球の列に含まれる交互列の長さの最大値を表す整数を1 行で出力せよ．
入出力例
入力例 1
10
1 1 0 0 1 0 1 1 1 0
出力例 1
7
これは問題文中で説明された例である．
入力例 2
10
1 0 0 0 0 1 0 1 0 1
出力例 2
8
西側から 4 番目の電球のみを操作すると，最大値 8 を満たす交互列が得られる．
入力例 3
5
1 1 0 1 1
出力例 3
5
西側から数えて 2 番目から 4 番目までの電球を操作すると，全ての電球からなる交互列を作ることがで
きる．
入力例 4
3
0 1 0
出力例 4
3
機械を使用しなくても良い場合があることに注意せよ．
問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include<sstream>
#include<list>
#include<iomanip>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <bitset>
#include <cassert>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
const int INF = 100000000;
const long long LINF = 3e18 + 7;
const int MAX_N = 10000010;
const int MAX_W = 10002;
const int MAX_ARRAYK = 100000;
double PI = 3.14159265358979323846;
//using ll = long long;

// poj3276
// 蟻本 p.139

int N;
int dir[MAX_N];

int main() {

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> dir[i];
	}

	vector<int> v;
	v.push_back(0);
	for (int i = 0; i < N - 1; i++) {
		if (dir[i] == dir[i + 1]) {
			v.push_back(i + 1);
		}
	}

	v.push_back(N);

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

	cout << ans << endl;

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3660
final_rank: 6

code_snippet: #include<iostream>

using namespace std;

int dp[100001][3];

int main()
{
	int N;
	cin >> N;
	int* a = new int[N];
	for (int i = 0; i < N; i++)
		cin >> a[i];
	dp[0][0] = 1;
	dp[0][1] = 1;
	dp[0][2] = 1;
	int ans = 1;
	for (int i = 1; i < N; i++)
	{
		if (a[i] == a[i - 1])
		{
			dp[i][0] = 1;
			dp[i][1] = dp[i - 1][0] + 1;
			dp[i][2] = dp[i - 1][1] + 1;
		}
		else
		{
			dp[i][0] = dp[i - 1][0] + 1;
			dp[i][1] = dp[i - 1][1] + 1;
			dp[i][2] = dp[i - 1][2] + 1;
		}
		ans = max(ans, max(dp[i][0], max(dp[i][1],dp[i][2])));
	}
	cout << ans << endl;

	//system("pause");
}
accuracy: 1
time_ms: 10
memory_kb: 4684
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <bitset>
#include <stack>
#include <queue>
#include <bits/stdc++.h>
//#include <atcoder/segtree>
#define rep(i, s, t) for(int i = (s); i <= (t); i++)
#define repd(i, s, t) for(int i = (s); i >= (t); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;


int main(){
  int n; cin >> n;
  vector<int> f(n);
  rep(i, 0, n-1){
    int buf; cin >> buf;
    if(i % 2 == 0) f[i] = (buf + 1)%2;
    else f[i] = buf;
  }

  vector<int> kogo(0);
  int cur_num = 0;
  int sum = 0;
  rep(i, 0, n-1){
    if(cur_num != f[i]){
      kogo.push_back(sum);
      cur_num = f[i];
      sum = 0;
    }
    sum++;
  }
  kogo.push_back(sum);

  int ans = 0;
  sum = 0;
  n = kogo.size();
  if(n < 3){
    rep(i, 0, n-1){
      sum += kogo[i];
    }
    cout << sum << endl;
    return 0;
  }

  rep(i, 0, n-3){
    sum = kogo[i] + kogo[i+1] + kogo[i+2];
    ans = max(ans, sum);
  }
  
  cout << ans << endl;
  
  //rep(i, 0, kogo.size()-1) cout << kogo[i] << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3604
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < N; i++)

int main()
{
  int N;
  cin >> N;
  int S[N];
  rep(i, N) cin >> S[i];
  vector<int> A;
  int prev = S[0];
  int cnt = 1;
  for (int i = 1; i < N; i++)
  {
    if (S[i] != prev)
    {
      cnt++;
    }
    else
    {
      A.push_back(cnt);
      cnt = 1;
    }
    prev = S[i];
  }
  A.push_back(cnt);
  /*
  rep(i, A.size())
  {
    cout << A[i] << " | ";
  }*/
  int maxv = 0;
  int tot = 0;
  if (A.size() <= 3)
  {
    rep(i, A.size())
    {
      tot += A[i];
    }
    cout << tot << endl;
    return 0;
  }
  else
  {
    maxv = A[0] + A[1] + A[2];
    rep(i, A.size() - 2)
    {
      maxv = max(maxv, A[i] + A[i + 1] + A[i + 2]);
    }
    cout << maxv << endl;
  }

}
accuracy: 1
time_ms: 10
memory_kb: 3672
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int n;
vector<int> a;
vector3d(int,dp,100001,2,2,-1);
int rec(int i,int rev,int used){
    if(i==n)return 0;
    if(dp[i][rev][used]!=-1)return dp[i][rev][used];
    if(rev==0){
        if(a[i]!=a[i+1])return dp[i][rev][used]=rec(i+1,0,used)+1;
        else{
            if(used)return dp[i][rev][used]=1;
            else return dp[i][rev][used]=rec(i+1,1,1)+1;
        }
    }else{
        if(a[i]!=a[i+1])return dp[i][rev][used]=rec(i+1,1,used)+1;
        else return dp[i][rev][used]=rec(i+1,0,used)+1;
    }
}

int main(){
    in(n);
    a.resize(n);
    in(a);
    int ans=0;
    rep(i,n){
        chmax(ans,rec(i,0,0));
        chmax(ans,rec(i,1,1));
    }
    out(ans);
}
accuracy: 1
time_ms: 20
memory_kb: 18328
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
using ll = long long;
const ll INF = 1e9+7;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    rep(i,n) cin >> s[i];
    vector<int> num;
    for(int i=0; i<n; ++i){
        int prev = i;
        while(i<n-1 && s[i]!= s[i+1]){
            i++;
        }
        num.push_back(i-prev+1);
    }

    ll ans = 0;
    if(num.size()<=2){
        for(auto x : num) ans += x;
        cout << ans << endl;
        return 0;
    }
    ans = num[0]+ num[1];
    for(int i=2; i<num.size(); ++i){
        ans = max(ans, (ll)num[i]+num[i-1]+num[i-2]);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3668
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
using namespace std;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<pair<int, int>>;
using VTIII = vector<tuple<int, int, int>>;
using Complex = complex<double>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a==b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a==b)){ a=b; return true; } return false; }
template<typename T> inline bool isin(const T& x, const T& l, const T& r){ return l <= x and x < r; }
inline ostream& fcout(int n = 10){ return cout << fixed << setprecision(n); }
inline ostream& rcout(int n = 2){ return cout << right << setw(n); }
constexpr int64_t INF = numeric_limits<int64_t>::max();
constexpr int32_t INF32 = numeric_limits<int32_t>::max();
constexpr int64_t MOD = 1000000007LL;
constexpr double PI = 3.14159265358979323846264338327950288;
constexpr double EPS = 1e-10;


int N;
VI v;


int32_t main(){
    cin >> N;
    int p = -1;
    v.push_back(0);
    v.push_back(0);
    rep(i, 0, N){
        int c;
        cin >> c;
        if(p != c) v.back()++;
        else v.push_back(1);
        p = c;
    }
    v.push_back(0);

    int ans = 0;
    rep(i, 1, SZ(v)-1) chmax(ans, v[i-1]+v[i]+v[i+1]);

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3460
final_rank: 2

code_snippet: #include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}

signed main() {
  int N;
  cin >> N;
  vector<int> light(N);
  vector<int> maxi_num_R(N);
  vector<int> maxi_num_L(N);

  rep(i, N) cin >> light[i];
  int maxi = 0;
  int L    = 0;
  int R    = 0;
  while (true) {
    maxi_num_R[R] = max(maxi_num_R[R], R - L + 1);
    maxi_num_L[L] = max(maxi_num_L[L], R - L + 1);
    if (R == N-1) break;
    if (light[R] != light[R + 1]) {
      R++;
    } else if (R == L) {
      R++;
      L++;
    } else {
      L++;
    }
  }
  maxi_num_R[N-1] = max(maxi_num_R[N-1], R-L+1);
  rep(i, N-1) maxi_num_L[i+1] = max(maxi_num_L[i+1], maxi_num_L[i]-1);
  R = L = 0;
  while (R != N - 1) {
    if (L != 0 and R != N - 1) maxi = max(maxi, R - L + 1 + maxi_num_R[L - 1] + maxi_num_L[R + 1]);
    if (L != 0) maxi = max(maxi, R - L + 1 + maxi_num_R[L - 1]);
    if (R != N - 1) maxi = max(maxi, R - L + 1 + maxi_num_L[R + 1]);
    if (light[R] != light[R + 1]) {
      R++;
    } else if (R == L) {
      R++;
      L++;
    } else {
      L++;
    }
  }
  cout << maxi << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 5116
final_rank: 16

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint N;
	cin >> N;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	vector<lint>B;
	int cnt = 1;
	rep(i, N-1) {
		if (A[i] == A[i + 1]) {
			B.push_back(cnt);
			cnt = 1;
		}
		else {
			cnt++;
		}
	}
	B.push_back(cnt);
	lint BS = B.size();
	
	lint ans = 0;
	if (BS == 1) {
		ans = B[0];
	}
	else if (BS == 2) {
		ans = B[0] + B[1];
	}
	else {
		rep(i, BS - 2) {
			ans = max(ans, B[i] + B[i + 1] + B[i + 2]);
		}
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3844
final_rank: 9

code_snippet: /* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    vector<int> B;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        cnt++;
        if (i == N-1 || A[i] == A[i+1]) {
            B.push_back(cnt);
            cnt = 0;
        }
    }

    int M = B.size();
    if (M < 3) {
        cout << N << endl;
        return 0;
    }

    int mx = -1;
    for (int i = 0; i < M-2; i++) {
        mx = max(mx, B[i] + B[i+1] + B[i+2]);
    }

    cout << mx << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4224
final_rank: 11

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

void chmax(int &a, int b){
    a = max(a,b);
}

bool solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<vector<int> > dp(n, vector<int>(3, 1));
    int ans = 1;
    for(int i=1;i<n;i++){
        if(a[i-1]!=a[i]){
            dp[i][0] = dp[i-1][0]+1;
            chmax(dp[i][1], dp[i-1][1]+1);
            chmax(dp[i][2], dp[i-1][2]+1);
        }else{
            chmax(dp[i][1], dp[i-1][0]+1);
            chmax(dp[i][2], dp[i-1][1]+1);
        }
        for(int j=0;j<3;j++){
            chmax(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
    return true;
}

int main(){
    solve();
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 8616
final_rank: 17

code_snippet: #include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
map<int, int>test;
map<int, int>uiop;
signed main() {
	int n, a, b = 0, c = 0, d = 0, ans = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a;
		if (h != 0) {
			if (b == a) {
				uiop[d] = h - 1;
				d++; c = 0;
				test[d] = h;
			}
		}
		b = a;
	}
	uiop[d] = n - 1; d++;
	/*for (int h = 0; h < d; h++) {
		cout << test[h] << ' ' << uiop[h] << endl;
	}*/
	for (int h = 0; h < d; h++) {
		ans = max(ans, uiop[h] - test[h - 2] + 1);
		ans = max(ans, uiop[h + 2] - test[h] + 1);
		ans = max(ans, uiop[h + 1] - test[h - 1] + 1);
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 9348
final_rank: 20

code_snippet: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
int n, a[123456], cnt;
vector<int>v;
signed main() {
	cin >> n;
	for0(i, n)cin >> a[i];
	cnt = 1;
	for1(i, n - 1) {
		if (a[i - 1] == a[i]) {
			v.push_back(cnt);
			cnt = 1;
		}
		else cnt++;
	}
	v.push_back(cnt);
	if (v.size() <= 2)cout << n << endl;
	else {
		int ans = 0;
		for (int i = 2; i < v.size(); i++) ans = max(ans, v[i - 2] + v[i - 1] + v[i]);
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 4216
final_rank: 10

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


int N;
int light[100005];
int dp[3][100005] = {};
int main() {
	cin >> N;
	rep(i, N) cin >> light[i];
	for (int i = 1; i < N; i++) {
		if (light[i - 1] != light[i]) {
			dp[0][i] = dp[0][i - 1] + 1;
			dp[1][i] = dp[1][i - 1] + 1;
			dp[2][i] = dp[2][i - 1] + 1;
		}
		else
		{
			dp[1][i] = dp[0][i - 1] + 1;
			dp[2][i] = dp[1][i - 1] + 1;
		}
	}
	int ans = 0;
	rep(i, 3)rep(j, N) ans = max(ans, dp[i][j]);
	cout << ans+1 << endl;

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4660
final_rank: 14

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N)cin >> A[i];
    vector<int> nums;
    int cnt = 0;
    rep(i,N){
        cnt++;
        if(A[i]==A[i+1]){
            nums.push_back(cnt);
            cnt=0;
        }
    }
    nums.push_back(cnt);
    int res = 0;
    for(int i=0;i+2<nums.size();i++){
        res = max(res,nums[i]+nums[i+1]+nums[i+2]);
    }
    if(nums.size()<3){
        rep(i,nums.size())res+=nums[i];
    }
    cout << res <<  endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3556
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n, m, a[112345];

int main(){
    cin >> n;
    --n;
    int prev;
    cin >> prev;
    REP(i, n){
      int tmp;
      cin >> tmp;
      if(prev == tmp){
        ++m;
      }else{
        ++a[m];
      }
      prev = tmp;
    }
    /*
    cout << m << endl;
    REP(i, m){
      cout << a[i] << " ";
    }
    */
    int ans = 0;
    REP(i, m + 1) ans = max(ans, a[i] + 1);
    REP(i, m) ans = max(ans, a[i] + a[i + 1] + 2);
    REP(i, m - 1) ans = max(ans, a[i] + a[i + 1] + a[i + 2] + 3);
    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3304
final_rank: 1

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    vector<vector<int>> dp(n, vector<int>(3, 1));
    int ans = 0;
    for(int i = 1; i < n; i++){
        dp[i][0] = a[i]!=a[i-1] ? dp[i-1][0]+1 : 1;
        dp[i][1] = a[i]!=a[i-1] ? dp[i-1][1]+1 : dp[i-1][0]+1;
        dp[i][2] = a[i]!=a[i-1] ? dp[i-1][2]+1 : dp[i-1][1]+1;
        ans = max({ans, dp[i][0], dp[i][1], dp[i][2]});
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 8684
final_rank: 18

code_snippet: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    vi v;
    int l = 0;
    rep(r,n-1){
        if(a[r] == a[r+1]){
            v.push_back(r+1-l);
            l = r+1;
        }
    }
    v.push_back(n-l);
    //rep(i,v.size())cout << " " << v[i];cout << endl;
    n = v.size();
    if(n == 1)cout << v[0] << endl;
    if(n == 2)cout << v[0] + v[1] << endl;
    if(n >= 3){
        int ans = 0;
        rep(i,n-2)ans = max(ans, v[i]+v[i+1]+v[i+2]);
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 4224
final_rank: 11

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;


int N;
int l[100001];
int dp[100001][3] = {};

int main() {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> l[i];
	}

	dp[1][0] = 1;
	dp[1][1] = 1;
	dp[1][2] = 1;

	for (int i = 2; i <= N; i++) {
		if (l[i] != l[i-1]) {
			dp[i][0] = dp[i - 1][0] + 1;
			dp[i][1] = dp[i - 1][1] + 1;
			dp[i][2] = dp[i - 1][2] + 1;
		}
		else {
			dp[i][0] = 1;
			dp[i][1] = dp[i - 1][0] + 1;
			dp[i][2] = dp[i - 1][1] + 1;
		}
	}

	int ans = 0;
	for (int i = 2; i <= N; i++) {
		for (int j = 0; j < 3; j++) {
			ans = max(ans, dp[i][j]);
		}
	}

	cout << ans << endl;


	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4652
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);


template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int N; cin >> N;
	V<int> a(N),b;
	REP(i,N) cin >> a[i];
	for(int i = 0; i < N; ++i){
		int cnt = 0;
		int j;
		for(j = i+1; j < N; ++j){
			if(a[j-1]==a[j]) break;
		}
		b.push_back(j-i);
		i = j-1;
	}
	corner(b.size()<=3,accumulate(ALL(b),0));
	int ans = 0;
	for(int i = 1; i + 1 < b.size(); ++i) chmax(ans,b[i-1]+b[i]+b[i+1]);
	cout << ans << endl;

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3584
final_rank: 4