use std::cmp::max; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut v = String::new(); std::io::stdin().read_line(&mut v).ok(); let v: Vec = v.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); if n == 1 { println!("{}", v[0]); return; } if n == 2 { println!("{}", max(v[0], v[1])); return; } let mut dp: Vec = vec![0; n]; dp[0] = v[0]; dp[1] = v[1]; dp[2] = v[0] + v[1]; for i in 3..n { dp[i] = max(dp[i-3]+v[i], max(dp[i-2]+v[i], dp[i-1])); } println!("{}", dp[n-1]); }