#include int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); int a[n + 1]; for (int i = 0; i < n; i++) a[i] = ri(); a[n] = -1; std::vector b; int last = 0; for (int i = 1; i <= n; i++) { if (a[i - 1] != a[i]) b.push_back(i - last), last = i; } n = b.size(); int dp[n + 1]; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) { // no use dp[i + 1] = std::max(dp[i + 1], dp[i]); // use dp[std::min(i + 2, n)] = std::max(dp[std::min(i + 2, n)], dp[i] + b[i]); } std::cout << dp[n] << std::endl; return 0; }