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)

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
    }


    let digit10 = [1_usize, 10, 100, 1000, 10000, 100000, 
                   1000000, 10000000, 100000000, 1000000000];
    let mut num3 = Vec::new();
    for digit in 1..10 {
        for p in 0..3_usize.pow(digit as u32){
            let mut num = p;
            let mut output = 0;
            for digit2 in 0..digit {
                output += [3, 5, 7][num % 3] * digit10[digit2];
                num /= 3;
            }
            num3.push(output);
        }
    }

    let mut num2 = Vec::new();
    for digit in 1..10 {
        for p in 0..2_usize.pow(digit as u32) {
            let mut num = p;
            let mut output35 = 0;
            let mut output57 = 0;
            let mut output73 = 0;
            for digit2 in 0..digit {
                output35 += [3, 5][num % 2] * digit10[digit2];
                output57 += [5, 7][num % 2] * digit10[digit2];
                output73 += [7, 3][num % 2] * digit10[digit2];
                num /= 2;
            }
            num2.push(output35);
            num2.push(output57);
            num2.push(output73);
        }
    }

    let mut num1 = Vec::new();
    for digit in 1..10 {
        let mut output3 = 0;
        let mut output5 = 0;
        let mut output7 = 0;
        for digit2 in 0..digit {
            output3 += 3 * digit10[digit2];
            output5 += 5 * digit10[digit2];
            output7 += 7 * digit10[digit2];
        }
        num1.push(output3);
        num1.push(output5);
        num1.push(output7);
    }

    let output = num3.iter().filter(|a| **a <= N).count() +
        num1.iter().filter(|a| **a <= N).count() -
        num2.iter().filter(|a| **a <= N).count();

    println!("{}", output);

}