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, fastout};
// use itertools::Itertools;

#[allow(dead_code)]
fn rec(v: &mut Vec<u32>, n: u32) -> u32 {
  let mut res = 0;
  for a in [3,5,7].iter() {
    v.push(*a);
    let mut val = 0;
    let mut inc = [false, false, false];
    for (t, x) in (0..v.len()).zip(v.iter()) {
      val += *x * 10u32.pow(t as u32);
      match *x {
        3 => inc[0] = true,
        5 => inc[1] = true,
        7 => inc[2] = true,
        _ => unreachable!()
      };
    }
    // dbg!(&v, val, &inc);
    if val <= n && inc.iter().all(|x| *x){
      res += 1;
    } else if val > n {
      v.pop();
      return res;
    }
    res += rec(v, n);
    v.pop();
  }
  res
}

fn rec2(current: u64, used: u8, n: u64) -> u32 {
  let mut ans = 0;
  if current <= n && used & 0b111 == 0b111 {
    ans += 1;
  } else if current > n {
    return 0;
  }
  ans += rec2(current * 10 + 3, used | 0b001, n);
  ans += rec2(current * 10 + 5, used | 0b010, n);
  ans += rec2(current * 10 + 7, used | 0b100, n);
  // for a in [3, 5, 7];
  ans
}

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

  // let mut v = Vec::new();
  // let ans = rec(&mut v, n as u32);
  let ans = rec2(0, 0, n as u64);
  println!("{}", ans);
}
*/

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