#![allow(unused_imports)] // use itertools::Itertools; // use proconio::{fastout, input, marker::*}; // #[fastout] fn main() { // input!{n:usize} let mut io = IO::new(); let n = io.next_usize(); let sz = n.to_string().len(); let mut ans = 0; for b in 0..4usize.pow(sz as u32) { let mut cur = String::from(""); let mut c = b; for _ in 0..sz { cur.push("0369".chars().collect::>()[c % 4]); c /= 4; } let cn = cur.parse::().unwrap(); if 102 <= cn && cn <= n { ans += 1; } } for i in (12..=99).step_by(3) { if i <= n { ans += 1; } } println!("{}",ans); } // copied IO from https://atcoder.jp/contests/abc234/submissions/28412243 pub struct IO { iter: std::str::SplitAsciiWhitespace<'static>, buf: std::io::BufWriter>, } impl Default for IO { fn default() -> Self { Self::new() } } impl IO { pub fn new() -> Self { use std::io::*; let mut input = String::new(); std::io::stdin().read_to_string(&mut input).unwrap(); let input = Box::leak(input.into_boxed_str()); let out = Box::new(stdout()); IO { iter: input.split_ascii_whitespace(), buf: BufWriter::new(Box::leak(out).lock()), } } pub fn next_str(&mut self) -> &str { self.iter.next().unwrap() } pub fn read(&mut self) -> T where ::Err: std::fmt::Debug, { self.iter.next().unwrap().parse().unwrap() } pub fn next_usize(&mut self) -> usize { self.read() } pub fn next_uint(&mut self) -> u64 { self.read() } pub fn next_int(&mut self) -> i64 { self.read() } pub fn next_float(&mut self) -> f64 { self.read() } pub fn next_chars(&mut self) -> std::str::Chars { self.next_str().chars() } pub fn next_vec(&mut self, n: usize) -> Vec where ::Err: std::fmt::Debug, { (0..n).map(|_| self.read()).collect::>() } pub fn print(&mut self, t: T) { use std::io::Write; write!(self.buf, "{}", t).unwrap(); } pub fn println(&mut self, t: T) { self.print(t); self.print("\n"); } pub fn print_iter>( &mut self, mut iter: I, sep: &str, ) { if let Some(v) = iter.next() { self.print(v); for vi in iter { self.print(sep); self.print(vi); } } self.print("\n"); } pub fn flush(&mut self) { use std::io::Write; self.buf.flush().unwrap(); } }