Problem:
Score : 300 points

Problem Statement

You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?

Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:

When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.

Constraints

1 \leq N < 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

Sample Input 1

575

Sample Output 1

4

There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.

Sample Input 2

3600

Sample Output 2

13

There are 13 Shichi-Go-San numbers not greater than 3600: the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.

Sample Input 3

999999999

Sample Output 3

26484

Solution in Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
#![allow(non_snake_case)]
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;

fn confirm_num(s: &str) -> bool {
    let mut flags = vec![false, false, false];
    for c in s.chars() {
        match c {
            '3' => flags[0] = true,
            '5' => flags[1] = true,
            '7' => flags[2] = true,
            _ => continue,
        }
    }
    if flags.iter().all(|&x| x == true) {
        true
    } else {
        false
    }
}

#[derive(Debug)]
struct Graph {
    s: String,
    ans: usize,
}

impl Graph {
    fn new() -> Graph {
        Graph {
            s: "".to_string(),
            ans: 0,
        }
    }

    fn dfs(&mut self, n: usize) {
        if self.s.len() > 0 {
            if self.s.parse::<usize>().unwrap() <= n {
                if confirm_num(&self.s) {
                    self.ans += 1;
                }
            } else {
                return
            }
        }

        for c in ['3', '5', '7'].iter() {
            self.s.push(*c);
            self.dfs(n);
            self.s.pop();
        }
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
    }

    let mut g = Graph::new();

    g.dfs(n);

    println!("{}", g.ans);
}
*/

fn main() {
    let exe = "/tmp/bin38750971";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";