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: Time Limit Exceeded)

use std::io;
use std::collections::{VecDeque};
use std::io::Write;

#[cfg(test)]
mod tests;

fn main() {
    // a();
    // b();
    c();
    // d();
}

fn a() {
    let mut buf = String::new();
    let handle = io::stdin();
    handle.read_line(&mut buf).unwrap();
    let n: isize = buf.trim().parse().unwrap();
    match n {
        3 | 5 | 7 => {
            println!("{}", "YES");
        },
        _ => {
            println!("{}", "NO");
        },
    }
}

fn b() { 
    let mut buf = String::new();
    let handle = io::stdin();
    handle.read_line(&mut buf).unwrap();
    let mut stock: VecDeque<u32> = buf.trim().chars()
        .map(|a| a.to_digit(10).unwrap()).collect();
    let mut num: VecDeque<isize> = VecDeque::with_capacity(3);
    for _ in 0..2 {
        let temp = stock.pop_front().unwrap(); 
        num.push_back(temp as isize);
    }
    let ideal_num = 753;
    let mut min_diff = 1000;
    for n in stock {
        num.push_back(n as isize);
        let dog_num = num[0] * 100 + num[1] * 10 + num[2];
        let diff = abs(ideal_num - dog_num);
        if min_diff > diff {
            min_diff = diff;
        }
        num.pop_front();
    }
    println!("{}", min_diff);
}

fn abs(n: isize) -> isize {
    if n >= 0 {
        n
    } else {
        -n
    }
}

fn c() { 
    let mut buf = String::new();
    let handle = io::stdin();
    handle.read_line(&mut buf).unwrap();
    let n: isize = buf.trim().parse().unwrap();

    let mut count = 0;
    for i in 1..n+1 {
        let num_str = format!("{}", i);
        let mut exist = vec![false, false, false, true];
        for c in num_str.chars() {
            match c {
                '7' => exist[0] = true,
                '5' => exist[1] = true,
                '3' => exist[2] = true,
                _ => exist[3] = false,
            }
        }
        if exist.iter().any(|&a| a == false) {
        } else {
            count += 1;
        }
    }
    println!("{}", count);
}
fn d() { 
}