fn main() { proconio::input! { n: usize, a: [i64; n], } let is_possible_from_front = a .iter() .scan(0, |acc, &x| { *acc = x.max(*acc - 1); Some(*acc <= 1) }) .collect::>(); let is_possible_from_back = a .iter() .rev() .scan(0, |acc, &x| { *acc = x.max(*acc - 1); Some(*acc <= 1) }) .collect::>(); if (0..n).any(|idx| is_possible_from_front[idx] && is_possible_from_back[idx]) { println!("Yes"); } else { println!("No"); } }