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:
/*
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn f(i: usize, n: i64) -> (bool, i64) {
    let mut v = vec![3; i];

    let mut res = 0;
    loop {
        let mut x = 0;
        let mut ten = 1;
        let mut t = [0; 10];
        for j in 0..i {
            t[v[j] as usize] += 1;
            x += ten * v[j];
            ten *= 10;
        }
        if x > n {
            return (true, res);
        }
        if t[3] * t[5] * t[7] != 0 {
            res += 1;
        }

        for j in 0..i {
            match v[j] {
                3 | 4 => {
                    v[j] = 5;
                    break;
                }
                5 | 6 => {
                    v[j] = 7;
                    break;
                }
                7 | 8 => {
                    if j + 1 == i {
                        return (false, res);
                    }
                    v[j] = 3;
                    v[j + 1] += 1;
                }
                _ => {}
            }
        }
    }
}

fn main() {
    input! {
        n: i64,
    }

    let mut res = 0;
    for i in 3.. {
        let (t, x) = f(i, n);
        // println!("{} {}", t, x);
        res += x;
        if t {
            break;
        }
    }
    println!("{}", res);
}
*/

fn main() {
    let exe = "/tmp/bin0572417B";
    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>";