use std::collections::VecDeque; use std::cmp::min; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: u32 = n.trim().parse().unwrap(); let pattern: Vec = vec![0,3,6,9]; let mut cands: VecDeque = VecDeque::new(); let mut result: u32 = 0; for i in 10..min(n+1, 100) { if i % 3 == 0 && (i % 10 + i / 10) % 3 == 0 { result += 1; } } cands.push_back(0); for i in 0..(n.to_string().len()) { let limit = cands.len(); for _ in 0..limit { let temp = cands.pop_front().unwrap(); for j in pattern.iter() { cands.push_back(temp + j * 10u32.pow(i as u32) as u32); } } } result += cands.iter().filter(|&i| i >= &100u32 && i <= &n).count() as u32; println!("{}", result); }