#include using namespace std; typedef long long ll; int main() { int N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } vector> b; b.push_back(make_pair(A[0], 1)); for (int i = 1; i < N; i++) { if (A[i] == (b.back()).first) { (b.back()).second++; } else { b.push_back(make_pair(A[i], 1)); } } int l = b.size(); int dp[l + 1]{}; dp[1] = b[0].second; if (l == 1) { cout << dp[1] << "\n"; return 0; } dp[2] = max(dp[1], b[1].second); for (int i = 2; i < l; i++) { dp[i + 1] = max(dp[i - 2], dp[i - 1]) + b[i].second; } cout << max(dp[l],dp[l - 1]) << "\n"; // for (auto i : b) { // cout << i.first << " " << i.second << "\n"; // } return 0; }