#include using namespace std; int main() { int n; cin >> n; vector a; int pre = 0, cnt = 1; cin >> pre; for(int i = 0; i < n - 1; ++i) { int aa; cin >> aa; if(pre != aa) { a.push_back(cnt); cnt = 1; pre = aa; } else { cnt++; } } a.push_back(cnt); for(int i : a) { cerr << i << endl; } int nn = a.size(); int dp[nn + 1] = {}; int maxi = 0; for(int i = 1; i <= nn; ++i) { dp[i] = maxi + a[i - 1]; dp[i] = max(dp[i], dp[i - 1] + a[i] - 1); // cout << dp[i] << endl; if(i - 1 >= 0) maxi = max(maxi, dp[i - 1]); } cout << dp[nn] << '\n'; return 0; }