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: Accepted)

//7550
//再帰関数
//感想：値を重複なしでカウントするのが大変//後ろにつけるだけでいい？
using System;
using System.Linq;
using System.Collections.Generic;

namespace tst
{
    class Program
    {
        public static int N = 0;
        public static int cnt = 0;
        public static bool Check(int v, int keta, bool alflag)
        {
            if (keta == 0)
            {
                return false;
            }
            else if (alflag == true)
            {
                //再帰前がすでに357入っていた時
                return true;
            }
            else
            {
                int[] K = new int[keta];
                //357ならK[0]=7,K[1]=5,K[2]=3
                for (int i = 0; i < keta; i++)
                {
                    K[i] = v%10;
                    v /= 10;
                }
                //フラグのリセット
                bool flag3 = false;
                bool flag5 = false;
                bool flag7 = false;
                foreach (int x in K)
                {
                    if (x == 3) flag3 = true;
                    else if (x == 5) flag5 = true;
                    else if (x == 7) flag7 = true;
                    else continue;
                }
                if (flag3 == true && flag5 == true && flag7 == true)
                {//357すべて含まれていたら返り値true
                    return true;
                }
                else return false;

            }
        } 
        static void Keisan(long v, int keta)
        {
            //Console.Write(v);
            if (v>N)
            {//終了条件
                //Console.WriteLine(" return");
                return;
            }
            bool alflag = false;
            //終了条件突破し、753数ならカウント増やす
            if (Check((int)v, keta, alflag))
            {
               // Console.WriteLine(" true");
                alflag = true;
                cnt++;
            }
            else
            {
                //Console.WriteLine(" false");
            }
            //末尾に3,5,7をつける
            Keisan(v * 10 + 3, keta + 1);
            Keisan(v * 10 + 5, keta + 1);
            Keisan(v * 10 + 7, keta + 1);

        }

        public static void Main()
        {
            //入力
            N = int.Parse(Console.ReadLine());
            //とりま準753数（333や57557含む）をゼロから始める
            Keisan(0, 0);
            //出力
            Console.WriteLine(cnt);
            
        }

    }
}