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 Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();
		List<String> list = new ArrayList<String>();
		String[] num = {"3", "5", "7"};
		for(int a = 0; a < 3; a++) {
			//list.add(num[a]);
			for(int b = 0; b < 3; b++) {
				//list.add(num[a] + num[b]);
				for(int c = 0; c < 3; c++) {
					list.add(num[a] + num[b] + num[c]);
					for(int d = 0; d < 3; d++) {
						list.add(num[a] + num[b] + num[c] + num[d]);
						for(int e = 0; e < 3; e++) {
							list.add(num[a] + num[b] + num[c] + num[d] + num[e]);
							for(int f = 0; f < 3; f++) {
								list.add(num[a] + num[b] + num[c] + num[d] + num[e] + num[f]);
								for(int g = 0; g < 3; g++) {
									list.add(num[a] + num[b] + num[c] + num[d] + num[e] + num[f] + num[g]);
									for(int h = 0; h < 3; h++) {
										list.add(num[a] + num[b] + num[c] + num[d] + num[e] + num[f] + num[g] + num[h]);
										for(int i = 0; i < 3; i++) {
											list.add(num[a] + num[b] + num[c] + num[d] + num[e] + num[f] + num[g] + num[h] + num[i]);
											for(int j = 0; j < 3; j++) {
												list.add(num[a] + num[b] + num[c] + num[d] + num[e] + num[f] + num[g] + num[h] + num[i] + num[j]);
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		List<Long> li = new ArrayList<Long>();
		//System.out.println(list.size());
		for(String t : list) {
			if(isCheck(t)){
				li.add(Long.parseLong(t));
			}
		}
		//System.out.println(li.size());
		int cnt = 0;
		for(Long i : li) {
			if(i <= N) {
				//System.out.println(i);
				cnt++;
			}
		}
		System.out.println(cnt);
	}
	static boolean isCheck(String t) {
		boolean flag1 = false;
		boolean flag2 = false;
		boolean flag3 = false;
		for(int i = 0; i < t.length(); i++) {
			char c = t.charAt(i);
			if(c == '3') {
				flag1 = true;
			}
			if(c == '5') {
				flag2 = true;
			}
			if(c == '7') {
				flag3 = true;
			}
			if(flag1 && flag2 && flag3) {
				return true;
			}
		}
		return false;
	}
}