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 C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Linq;
using System.Collections.Generic;

namespace Atcoder
{
    class Program2
    {
        public static void Main(string[] args)
        {
            long N = int.Parse(Console.ReadLine());
            List<long> list = new List<long>();
            for (int a = 0; a < 8;a=Generatei(a)){
                for (int b = 0; b < 8; b = Generatei(b))
                {
                    for (int c = 0; c < 8; c = Generatei(c))
                    {
                        for (int d = 0; d < 8; d = Generatei(d))
                        {
                            for (int e = 0; e < 8; e = Generatei(e))
                            {
                                for (int f = 0; f < 8; f = Generatei(f))
                                {
                                    for (int g = 3; g < 8; g = Generatei(g))
                                    {
                                        for (int h = 3; h < 8; h = Generatei(h))
                                        {
                                            for (int i = 3; i < 8; i = Generatei(i))
                                            {
                                                long judgedNumber = a * 100000000 + b * 10000000 + c * 1000000 + d * 100000 + e * 10000 + f * 1000 + g * 100 + h * 10 + i;
                                                if(Judge(judgedNumber)){
                                                    list.Add(judgedNumber);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            int count = 0;
            while(list[count]<=N&&count<list.Count){
                count++;
            }
            Console.WriteLine(count);
        }
        public static int Generatei(int i){
            if(i==0){
                return 3;
            }else if(i==3){
                return 5;
            }else if(i==5){
                return 7;
            }else if(i==7){
                return 8;
            }
            return 0;
        }
        public static bool Judge(long b){
            bool is3appear = false;
            bool is5appear = false;
            bool is7appear = false;
            for (int j = 0; j < b.ToString().Length; j++)
            {
                int a = int.Parse(b.ToString().Substring(j, 1));
                if (a == 3)
                {
                    is3appear = true;
                }
                else if (a == 5)
                {
                    is5appear = true;
                }
                else if (a == 7)
                {
                    is7appear = true;
                }
            }

            if (is3appear == true && is5appear == true && is7appear == true)
            {
                return true;
            }else{
                return false;
            }
        }
    }
}