use std::io::Read; use std::cmp; fn main() { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let sushi_lane: Vec = iter .map(|v| v.parse::().unwrap()) .collect(); println!("{}", calc_max(&sushi_lane, 0, n-1)); } fn calc_max(sushi_lane: &Vec, pos: usize, tail: usize) -> usize { if pos == tail { return sushi_lane[tail] } else if pos > tail { return 0 } let left_max: usize = sushi_lane[pos] + calc_max(sushi_lane, pos+2, tail); let right_max: usize = sushi_lane[pos+1] + calc_max(sushi_lane, pos+3, tail); cmp::max(left_max, right_max) }