use std::io::*; use std::str::*; use std::cmp::max; #[allow(dead_code)] fn get_line(sl: &mut StdinLock) -> String { let mut line = String::new(); sl.read_line(&mut line).expect("cannot read line"); line.trim().to_string() } #[allow(dead_code)] fn cast(s: &str) -> T { s.parse().ok().expect("cannot cast from str") } #[allow(dead_code)] fn get_vec(sl: &mut StdinLock, n: usize) -> Vec { (&get_line(sl)).split(' ').map(cast::).take(n).collect() } fn run(sl: &mut StdinLock) { let n = cast::(&get_line(sl)); let vs = get_vec::(sl, n); let mut dp = vec![0; n + 1]; dp[0] = 0; dp[1] = vs[0]; (2..=n).for_each(|i| { dp[i] = max(dp[i - 2] + vs[i - 1], dp[i - 1]); }); println!("{}", dp[n]); } fn main() { let s = stdin(); let mut sl = s.lock(); run(&mut sl); }