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)

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramC a = new ProgramC();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            int n = int.Parse(Console.ReadLine());

            if (n == 3 || n == 5 || n == 7)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }

    class ProgramB
    {
        public void main()
        {

            //入力
            string s = Console.ReadLine();

            int ans = 1000;

            for (int i = 0; i < s.Length - 2; i++)
            {
                int t = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
                t = Math.Abs(t - 753);
                ans = Math.Min(t, ans);
            }



            //答え出力
            Console.WriteLine(ans);


        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            string s = Console.ReadLine();
            long n = long.Parse(s);
            int ans = 0;
            //どれかを選んでみる
            for (int i = 3; i <= s.Length; i++)
                for (int j = 0; j < (int)Math.Pow(3, i); j++)
                {
                    //3進数換算
                    int[] array = new int[i];
                    int kisu = j;
                    for(int k = 0;k < i;k++)
                    {
                        array[k] = kisu % 3;
                        kisu /= 3;
                    }

                    //この3進数が満たすか確認
                    int[] count = new int[3];
                    for (int k = 0; k < i; k++)
                    {
                        for (int l = 0; l < 3; l++)
                        {
                            if (array[k] == l)
                                count[l]++;
                        }
                    }
                    //確認どれか0ならあり得ない
                    int flag = 0;
                    for (int l = 0; l < 3; l++)
                    {
                        if (count[l] == 0)
                            flag = 1;
                    }

                    if (flag == 1)
                        continue;

                    //最後にn以下か確認
                    long b = 1;
                    long num = 0;
                    for(int k = 0;k < i;k++)
                    {
                        if (array[k] == 0)
                            num += 3 * b;
                        if (array[k] == 1)
                            num += 5 * b;
                        if (array[k] == 2)
                            num += 7 * b;

                        b *= 10;
                    }

                    if (num <= n)
                        ans++;


                }

            //答え出力
            Console.WriteLine(ans);


        }


    }





    class ProgramD
    {
        public void main()
        {

            //入力
            string[] s = Console.ReadLine().Split(' ');
            long a = long.Parse(s[0]);
            long b = long.Parse(s[1]);


            //F(A,B) は F(0,A-1)とF(0,B)との排他的論理和（よってF(0,n)を考える）
            //排他的論理和はどっからでも足してよい。また任意の偶数nにおいてnとn+1の排他的論理和は1である。

            long ta = 0;
            long tb = 0;
            //a-1を出す
            if (a == 0)
            {

            }
            else if ((a - 1) % 2 == 1)
            {
                if ((a / 2) % 2 == 1)
                    ta = 1;
            }
            else
            {
                if (((a - 1) / 2) % 2 == 1)
                    ta = a;
                else
                    ta = a - 1;
            }

            //bを出す
            if (b % 2 == 1)
            {
                if (((b + 1) / 2) % 2 == 1)
                    tb = 1;
            }
            else
            {
                if ((b / 2) % 2 == 1)
                    tb = b + 1;
                else
                    tb = b;
            }

            //taとtbの排他的論理和を求める
            long ans = (ta ^ tb);

            //答え出力
            Console.WriteLine(ans);

        }

    }


}