#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; vector> v = {{A[0], 1}}; for(int i = 1; i < N; i++) { if(v.back().first == A[i]) v.back().second++; else v.push_back({A[i], 1}); } A.clear(); for(auto [x, c] : v) A.push_back(c); N = int(A.size()); int dp[N + 1][2] = {}; for(int i = 0; i < N; i++) { dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + A[i]); dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][0], dp[i][1])); } cout << max(dp[N][0], dp[N][1]) << "\n"; }