#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let n = read::(); let a = read_vec::(); let mut unique = vec![1]; for i in 1..n { if a[i] == a[i - 1] { let last = unique.len() - 1; unique[last] += 1; } else { unique.push(1); } } if unique.len() == 1 { println!("{}", unique[0]); return; } let mut dp = vec![0; unique.len() + 1]; dp[0] = 0; dp[1] = unique[0]; dp[2] = unique[1]; for i in 2..unique.len() { dp[i + 1] = unique[i] + max(dp[i - 1], dp[i - 2]); } println!("{}", max(dp[dp.len() - 1], dp[dp.len() - 2])); } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }