#include using namespace std; int main(){ long N; cin >> N; long cnt = 0; long last = -1; vector Acnt; while(N--){ long a; cin >> a; if(a == last) cnt++; else{ if(last != -1) Acnt.push_back(cnt); cnt = 1; last = a; } } Acnt.push_back(cnt); if(Acnt.size() == 1){ cout << N << '\n'; return 0; } vector dp(Acnt.size(), 0); dp[0] = Acnt[0]; if(1 < Acnt.size()) dp[1] = Acnt[1]; if(2 < Acnt.size()) dp[2] = max(dp[0] + Acnt[2], dp[1]); for(long i = 3; i < Acnt.size(); i++){ dp[i] = max(dp[i], dp[i - 2] + Acnt[i]); dp[i] = max(dp[i], dp[i - 3] + Acnt[i]); } cout << max(dp[Acnt.size() - 2], dp[Acnt.size() - 1]) << '\n'; }