use std::collections::VecDeque; fn main() { let mut p = String::new(); std::io::stdin().read_line(&mut p).ok(); let p = p.trim().chars().map(|c| c as usize - '0' as usize).collect::>(); if p.len() == 1 { println!("No"); return; } else if p.len() == 2 { if p[1] == 2 || p[1] == 3 || p[1] == 4 { if p[0] == 1 || p[0] == 7 || p[0] == 8 { println!("Yes"); return; } } } else { let n = p.len()-1; if p[n] == 2 || p[n] == 3 || p[n] == 4 { if p[0] == 1 || p[0] == 6 || p[0] == 7 || p[0] == 8 { let end = (1..n).filter(|&i| p[i] == 3 || p[i] == 4 || p[i] == 5).nth(0).unwrap_or(n); let end_ok = (end..n).filter(|&i| p[i] == 3 || p[i] == 4 || p[i] == 5).count() == n-end; let middle_ok = end == 1 || p[end-1] == 7 || p[end-1] == 8; let start_ok = (end == 1 && p[0] != 6) || end == 2 || (1..=end-2).filter(|&i| p[i] == 6 || p[i] == 7).count() == end-2; if end_ok && middle_ok && start_ok { println!("Yes"); return; } } } } println!("No"); }