#include #include #include using namespace std; int dp[100100][2]; // int a[100100]; void chmax(int &a, int b){ if( a < b){swap(a,b);} return ;} int main(){ int n; scanf("%d", &n); for(int i = 0; i < n; i++){ scanf("%d", &a[i]);} dp[0][1] = 1; //dynamic programming for(int i = 0; i < n-1; i++){ chmax(dp[i+1][0], dp[i][1]); chmax(dp[i+1][0], dp[i][0]); chmax(dp[i+1][1], dp[i][0]+1); if( a[i] == a[i+1]){ chmax(dp[i+1][1], dp[i][1]+1); } } int res = max(dp[n-1][0],dp[n-1][1]); printf("%d\n", res); return 0; }