use std::io::{self, BufReader, BufWriter, Read, Write}; fn main() { let stdin = io::stdin(); let mut stdin = BufReader::new(stdin.lock()); let stdout = io::stdout(); let mut stdout = BufWriter::new(stdout.lock()); let a = read_u64(&mut stdin); let b = read_u64(&mut stdin); (a..b + 1) .filter(|x| is_multiple_of_three(*x) || is_include_three(*x)) .for_each(|x| writeln!(&mut stdout, "{}", x).unwrap()); } fn read_u64(reader: &mut R) -> u64 { reader .bytes() .filter_map(|b| b.ok()) .skip_while(|b| b.is_ascii_whitespace()) .take_while(|b| !b.is_ascii_whitespace()) .map(|b| (b - 48) as u64) .fold(0, |acc, x| acc * 10 + x) } fn is_multiple_of_three(x: u64) -> bool { x % 3 == 0 } fn is_include_three(x: u64) -> bool { let mut n = x; while n != 0 { if n % 10 == 3 { return true; } n /= 10; } false }