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 (Python):
from itertools import product

def read():
    N = int(input())
    return N,

def solve(N):
    count = 0
    for i in range(3, 10):
        for x in product('357',repeat=i):
            if all(x.count(d) for d in '357'):
                if int(''.join(x), 10) <= N:
                    count += 1
    return count

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Solution (Python):
from itertools import product

def read():
    N = int(input())
    return N,

def solve(N):
    count = 0
    for i in range(3, 10):
        for x in product('357',repeat=i):
            if '3' in x and '5' in x and '7' in x:
                if int(''.join(x), 10) <= N:
                    count += 1
    return count

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)

N = 0
ans = 0


def isOK(n):
    m = set()
    for s in str(n):
        m.add(s)
    if len(m) != 3:
        return False
    if '3' in m and '5' in m and '7' in m:
        return True
    return False


def rec(n):
    global ans
    global N
    if n > N:
        return
    if isOK(n):
        ans += 1
    rec(n * 10 + 3)
    rec(n * 10 + 5)
    rec(n * 10 + 7)


def solve():
    global N
    N = Scanner.int()
    rec(0)
    print(ans)


def main():
    
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())


def dfs(s):
    if int(s) > N:
        return 0

    ret = 1 if all(s.count(c) > 0 for c in '753') else 0  
    for c in '753':
        ret += dfs(s + c)
    return ret


print(dfs('0'))

Solution (Python):
import itertools

if __name__ == "__main__":
    n = input()

    if len(n) < 3:
        print(0)
        exit()

    ans = 0
    seq = ['0', '3', '5', '7']

    tmp = list(itertools.product(seq, repeat=len(n)))

    for t in tmp:
        if int(''.join(t)) <= int(n):
            a = str(int(''.join(t)))
            if '0' not in a and len(set(a)) == 3:
                ans += 1

    print(ans)

Solution (Python):
N=int(input())

def dfs(s):
  if int(s)>N:
    return 0
  ret=1 if all(s.count(c)>0 for c in '753') else 0
  for c in '753':
    ret+=dfs(s+c)
  return ret

print(dfs('0'))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()

ans=0

chk=True
cnt=0
while chk:
    cnt+=1
    for i in product([3,5,7],repeat=cnt):
        if 3 in i and 5 in i and 7 in i:
            if n>=int("".join(map(str, i))):
                ans+=1
            else:
                chk=False
print(ans)

Solution (Python):
from collections import Counter

m = input()
x = int(m)
n = len(m)
d = [3,5,7]
ans2 = []

def dfs( n , s ):
    if s // (10**(n-1)) != 0:
        ans.append(s)
        return
    else:
        for j in d:
            dfs( n , s*10+j )
            
def kak(n,lis):
    for l in range(len(lis)):
        a = [0] * 10
        c = lis[l]
        for _ in range(n):
            b = c % 10
            a[b] += 1
            c //= 10
            
        if a[3] != 0 and a[5] != 0 and a[7] != 0:
            ans2.append(lis[l])
            
for i in range(n+1):
    ans = []
    dfs(i,0)
    kak(i,ans)

ta = 0
for i in ans2:
    if x >= i:
        ta += 1
        
print(ta)

Solution (Python):
n = int(input())
s = [3,5,7]

ans = 0
a = [""]
for i in range(len(str(n))):
    b = []
    for j in a:
        for k in s:
            k1 = int(j + str(k))
            b.append(str(k1))
            if k1 <= n and "3" in str(k1) and "5" in str(k1) and "7" in str(k1):
                ans += 1
    a = b

print(ans)

Solution (Python):
n = input()
length0 = len(n)
ans = 0

for h in range(3,length0 + 1):
    if h == length0:
        N = n
    else:
        N = "9"*h

    length = len(N)

    dp = [[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(length+1)]
    dp[0][0][0][0][0] = 1

    s1 = [3,5,7]
    for i in range(length):
        max_digit = int(N[i])
        for flag_less in range(2):
            for flag_siti in range(2):
                for flag_go in range(2):
                    for flag_san in range(2):
                        range_digit = s1 if flag_less else [i for i in s1 if i <= max_digit]
                        for d in range_digit:
                            flag_less_next = 0
                            flag_siti_next = 0
                            flag_go_next = 0
                            flag_san_next = 0
                            if flag_less == 1 or d < max_digit:
                                flag_less_next = 1
                            if flag_siti == 1 or d == 7:
                                flag_siti_next = 1
                            if flag_go == 1 or d == 5:
                                flag_go_next = 1
                            if flag_san == 1 or d == 3:
                                flag_san_next = 1
                            dp[i+1][flag_less_next][flag_siti_next][flag_go_next][flag_san_next] += dp[i][flag_less][flag_siti][flag_go][flag_san]

    ans += (dp[length][0][1][1][1] + dp[length][1][1][1][1])

print(ans)

Solution (Python):
n = int(input())

def dfs_stack(x): 
    ans = 0
    stack = []
    stack.append(0)
    while stack:
        i = stack.pop()
        if i > n:
            continue
        ans += 1 if judge(i) else 0
        stack.append(int(str(i) + "3"))
        stack.append(int(str(i) + "5"))
        stack.append(int(str(i) + "7"))
    print(ans)
    
def judge(x:int) -> bool: 
    if set(str(x)) == {"3", "5", "7"}:
        return True
    else:
        return False    

dfs_stack(n)

Solution (Python):
n = int(input())

def dfs(s):
    if int(s) >n:
        return 0
    
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(s+c)
    
    return ret

print(dfs('0'))

Solution (Python):
n = int(input())
ans = 0

def dfs(x:int): 
    global ans
    if x > n:
        return
    if judge(x):
        ans += 1
    for i in "357":
        dfs(int(str(x) + i))

def judge(x): 
    if set(str(x)) == {"3", "5", "7"}:
        return True
    else:
        return False

dfs(0)
print(ans)

Solution (Python):
from itertools import product

n = int(input())
res = 0
for pattern in product(["0", "3", "5", "7"], repeat=9):
    p = int("".join(pattern))
    if "0" not in str(p):
        for i in [3, 5, 7]:
            if str(i) not in str(p):
                break
        else:
            if p <= n:
                res += 1
            else:
                break
print(res)

Solution (Python):
import math
import collections
from operator import mul
from functools import reduce
import bisect

b=[]
def test(a):
    if len(a)>=8:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
    else:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
        test(a+"3")
        test(a+"5")
        test(a+"7")



n=int(input())
test("")
c=[]
b=set(b)
for bi in b:
    if bi.count("3")>0 and  bi.count("5")>0 and bi.count("7")>0 :
        c.append(bi)

c=sorted(list(map(int,c)))
d=bisect.bisect(c,n)
print(d)

Solution (Python):
N = int(input())

def dfs(n):
  ans = 0
  if n > N:
    return 0
  else:
    if all(str(n).count(c) > 0 for c in "357"):
      ans = 1
    ans += dfs(10*n + 3)
    ans += dfs(10*n + 5)
    ans += dfs(10*n + 7)
  return ans

print(dfs(0))

Solution (Python):
N = int(input())
ans = 0

def dfs(n):
  global ans
  if n > N:
    return
  else:
    if all(str(n).count(c) > 0 for c in "357"):
      ans += 1
    dfs(10*n + 3)
    dfs(10*n + 5)
    dfs(10*n + 7)

dfs(0)
print(ans)

Solution (Python):
import itertools
n = int(input())
num = 4**9
ans = 0
for i in range(num):
    a = 0
    b = 0
    c = 0
    d = 0
    s = i
    for j in range(9):
        a += 0 * int(s % 4 == 0) * 10 ** j
        b += 3 * int(s % 4 == 1) * 10 ** j
        c += 5 * int(s % 4 == 2) * 10 ** j
        d += 7 * int(s % 4 == 3) * 10 ** j
        s = s // 4
    tmp = a + b + c + d
    if tmp > n:
        break
    tmp = str(tmp)
    if b > 0 and c > 0 and d > 0 and tmp.count('0') == 0:
        ans += 1
print(ans)

Solution (Python):
n=int(input())
a=[]
ans=0

def search(count):
    global ans
    
    if int(count)>n:
        return 
    
    if set(sorted(list(count))) =={"0","3","5","7"}:
        ans+=1

    for i in "357":
        search(count+i)


search("0")
print(ans)

Solution (Python):
N= int(input())
def f(x):
    z=0
    if int(x) >N:
        return 0
    if x.count('3')>0 and x.count('5')>0 and x.count('7')>0:
        z = 1
    z +=f(x+'3')
    z +=f(x+'5')
    z +=f(x+'7')
    return z
print(f('0'))

Solution (Python):
N = input()

num = len(N)
N = int(N)

def calc(s):
    c = 0
    for i, j in enumerate(s):
        c +=  int(j) * 10**(num-i-1)
    return c

temp = ['0', '3', '5', '7']
ans = 0

while temp:
    p = temp.pop()
    if len(p)==num:
        if set(list(p)) == {'3', '5', '7'} or set(list(p)) == {'3', '5', '7', '0'}:
            ans += 1
    else:    
        if set(list(p))=={'0'}:
            temp.append(p+'0')
        for i in ('3', '5', '7'):
            if calc(p+i)<=N:
                temp.append(p+i)
            
print(ans)

Solution (Python):
def getSpecialNum(x, n):	
	if int(x) > n:
		return 0
	ans = 0
	if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
		ans = 1
	ans += getSpecialNum(x+'3',n)
	ans += getSpecialNum(x+'5',n)
	ans += getSpecialNum(x+'7',n)
	return ans
N = int(input())
print(getSpecialNum('0',N))

Solution (Python):
import sys







import itertools





readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    nl = len(str(n))
    nums = [3, 5, 7]
    ans = 0



    for i in range(3, nl+1):
        a = itertools.product(nums, repeat=i)
        for elem in a:
            if len(set(elem)) == 3:
                x = ""
                for num in elem:
                    x += str(num)
                x = int(x)
                if x <= n:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
limit = int(input())



def dfs(s):
	if int(s)>limit:
		return 0

	ret = 1 if all(s.count(c)>0 for c in "753") else 0
	for c in "753":
		ret += dfs(s+c)
	return ret
print(dfs("0"))

Solution (Python):
N = input()
keta = len(N)
candidate = []

def dfs(s, level):
    if level == keta + 1:
        return
    
    if s=='':
        pass
    else:
        candidate.append(int(s))

    dfs(s + '3', level+1)
    dfs(s + '5', level+1)
    dfs(s + '7', level+1)

dfs('', 0)
ans = 0
for d in candidate:
    group = set(str(d))
    if (group == {'3', '5', '7'}) and (d<=int(N)):
        ans += 1
print(ans)

Solution (Python):
N=int(input())
res =[0]
def rep(n,ans):
    if len(set(str(n)))==3 and n<=N:
        res[0]+=1
        return rep(n*10+3,ans+1)+rep(n*10+5,ans+1)+rep(n*10+7,ans+1)
    elif n<=N:
        for i in [3,5,7]:
            return sum([rep(n*10+i,ans) for i in [3,5,7]])
    else:
        return ans
for i in [3,5,7]:
    rep(i,0)
print(res[0])

Solution (Python):
n = 0
ans = 0
def dfs(s):
    ret = 0
    if int(s) <= n:
        if '7' in s and '5' in s and '3' in s:
            ret += 1
        ret += dfs(s+'7')
        ret += dfs(s+'5')
        ret += dfs(s+'3')
    return ret

n = int(input())
print(dfs('0'))

Solution (Python):
n = int(input())
def f(s):
  if int(s) > n:
    return 0 
  if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
  	cnt = 1
  else:
  	cnt = 0
  cnt += f(s + "3")
  cnt += f(s + "5")
  cnt += f(s + "7")
  return cnt
  
result = f("0")
print(result)

Solution (Python):

N=int(input())
M=["3","5","7"]
S=""

def dfs (S, N):
  global ans
  for m in M:
    T=m+S
    
    if int(T)>N:
      continue
    else:
      
      if len(set(T))==3:
        ans+=1
        
      
      dfs(T, N)
  return
ans=0
dfs(S, N)
print(ans)

Solution (Python):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    N = int(input())
    ans = 0
    for digits in range(1, 10):
        for i in range(3 ** digits):
            num = []
            for j in range(digits):
                k = i
                for _ in range(j):
                    k //= 3
                if k % 3 == 0:
                    num.append(7)
                elif k % 3 == 1:
                    num.append(5)
                else:
                    num.append(3)
            if all(j in num for j in [3, 5, 7]):
                num = reduce(lambda x, i: x * 10 + i, num)
                if num <= N:
                    ans += 1
    print(ans)



main()

Solution (Python):
from itertools import product

N = int(input())
ans = 0
for j in range(3, len(str(N))+1):
    for i in product("357", repeat=j):
        x = "".join(i)
        if 357 <= int(x) <= N and len(set(x)) == 3:
            ans += 1
print(ans)

Solution (Python):
N = int(input())

def dfs(a):
    if int(a) > N:
        return 0    
    if '7' in a and '5' in a and '3' in a:
        ans = 1
    else:
        ans = 0
    ans += dfs(a+'7')
    ans += dfs(a+'5')
    ans += dfs(a+'3')
    return ans

print(dfs('0'))

Solution (Python):
def dfs(s,n):
    if int(s)>n:
        return 0
    ans=1000000
    if(s.count('7')>0 and s.count('5')>0 and s.count('3')>0):
        ans=1
    else:
        ans=0
    for c in '357':
        ans+=dfs(s+c,n);
    return ans
    
    
n=int(input())
print(dfs('0',n))

Solution (Python):
N = int(input())
def dfs(s):
    if int(s)>N:
        return 0;
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(s+c)
    return ret
print(dfs("0"))

'''
>>> s = 'aAaAAbAccdd'

>>> s.count('A') 

>>> a = [True, True, True]
>>> all(a) 
>>> b = [True, True, False]
>>> all(b) 
'''

Solution (Python):
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    cnt = [0]

    def check(s=""):
        if int(s) > N:
            return 0
        rt = 1 if all(s.count(c) > 0 for c in '753') else 0
        for c in '753':
            rt += check(s + c)
        return rt

    print(check("0"))


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
from itertools import product
ans = 0
for n in range(3,10):
    for ptn in product('753', repeat=n):
        if '7' not in ptn: continue
        if '5' not in ptn: continue
        if '3' not in ptn: continue
        v = int(''.join(ptn))
        if v <= N:
            ans += 1
print(ans)

Solution (Python):
N = int(input())

def dfs(n):
    if int(n) > N:
        return 0

    if all(n.count(i)>0 for i in "753"):
        ret = 1
    else:
        ret = 0
        
    for i in "753":
        ret += dfs(n+i)

    return ret

print(dfs("0"))

Solution (Python):
n=input()
A=[0,1,2,3,4,5,6,7,8,9]
B=[0,0,0,1,1,2,2,3,3,3]
N=[]
a=0
for i in range(len(n)):
  if a==1:
    N.append(3)
  elif int(n[i]) in {0,3,5,7}:
    N.append(B[int(n[i])])
  else:
    N.append(B[int(n[i])])
    a=1
NN=0
for i in range(len(N)):
  NN=NN+N[-1-i]*4**i
ans=0
for i in range(NN+1):
  S=[]
  j=i
  while j>0:
    k=j%4
    S.append(k)
    j=j//4
  s=set(S)  
  if s=={1,2,3}:
    ans=ans+1
print(ans)

Solution (Python):
def search(s, n):
  if int(s) > n:
    return 0
  ans = 1 if (s.count('7') > 0 and s.count('5') > 0 and s.count('3') > 0) else 0
  for c in '753':
    ans += search(s+c,n)
  return ans

N = int(input())
print(search('0',N))

Solution (Python):





from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product


import sys
sys.setrecursionlimit(10 ** 5 + 10)


def resolve():
    N = input()
    long=len(N)
    M= int(N)

    seq=(3,5,7)
    cnt=0
    for j in range(3,long+1):
        for i in product(seq,repeat=j):
            if i.count(3)>=1 and i.count(5)>=1 and i.count(7)>=1\
                    and int(''.join(str(j) for j in i))<=M:
                cnt+=1
    print(cnt)




resolve()

Solution (Python):
n = int(input())
def f(s):
  if int(s) > n:
    return 0 
  if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
  	cnt = 1
  else:
  	cnt = 0
  cnt += f(s + "3")
  cnt += f(s + "5")
  cnt += f(s + "7")
  return cnt
  
result = f("0")
print(result)

Solution (Python):
n=int(input())
from itertools import product as p
l=['7','5','3']
a=[]
for i in range(1,11):
  for j in p(l,repeat=i):
    t=''.join(j)
    if '3' in t and '5' in t and '7' in t:
      a.append(int(t))
a.sort()
from bisect import bisect_right as bi
print(bi(a,n))

Solution (Python):
from itertools import product

N = int(input())
ans, L = 0, len(str(N))
for i in range(L + 1):
    for p in product(("7", "5", "3"), repeat=i):
        if "7" in p and "5" in p and "3" in p:
            if (i == L and int(''.join(p)) <= N) or i < L:
                ans += 1
print(ans)

Solution (Python):
from collections import deque
data = deque()
num = [3,5,7]
def shiti(n):
    data.append(n)
    if n<=10**9:
        for i in range(3):
            shiti(n*10+num[i])
shiti(0)
data = list(data)
data = sorted(data)

N = int(input())
cnt = 0
for i in range(len(data)):
    if data[i] > N: break
    ni = list(str(data[i]))
    if "3" in ni and "5" in ni and "7" in ni:
        cnt += 1

print(cnt)

Solution (Python):
n = int(input())

import itertools
import collections

ref = ['7','5','3']

arr = []
for i in range(3,10):
    arr += list(itertools.product(ref, repeat=i))

ans = []
for i in range(len(arr)):
    c = arr[i]
    if '3' in c and '5' in c and '7' in c:
        t = ''.join(list(c))
        if int(t) <= n:
            ans.append(int(t))


ans.sort()
print(len(ans))

Solution (Python):
n = int(input()) 
def dfs(s): 
    if int(s) > n: 
        return 0 
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1 
    else:
        cnt = 0 
    cnt += dfs(s + '3') 
    cnt += dfs(s + '5') 
    cnt += dfs(s + '7')
    return cnt 
  
print(dfs('0'))

Solution (Python):
n = int(input()) 
def dfs(s):
    if int(s) > n:
        return 0 
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1 
    else:
        cnt = 0
    cnt += dfs(s + '3') 
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt 
  
print(dfs('0'))

Solution (Python):
n = int(input())
 
def dfs(s):

    if int(s) > n:
        return 0
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1
    else:
        cnt = 0
    cnt += dfs(s + '3')
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt
  
print(dfs('0'))

Solution (Python):
def dfs(s): 
  if int(s) > N:
    return 0
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0 
  for c in '753':
    ret += dfs(s + c)
  return ret

N = int(input())
print(dfs('0'))

Solution (Python):
import itertools
N=int(input())
words=['3','5','7']
mojiretu=[]
for a in range(1,10):
    answers = list(itertools.product(words, repeat=a))
    for a in answers:
        moji = ''
        for b in a:
            moji += b
        mojiretu.append(moji)
S=[]
for a in mojiretu:
    number=0
    suuji=0
    kazu=0
    for b in a:
        if b=='3':
            number+=1
        elif b=='5':
            suuji+=1
        elif b=='7':
            kazu+=1
    if number>=1 and suuji>=1 and kazu>=1:
        S.append(int(a))
T=[i for i in S if i<=N]
print(len(T))

Solution (Python):
N = int(input())
def dfs(s):
    if int(s)>N:
        return 0;
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(s+c)
    return ret
print(dfs("0"))

Solution (Python):
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    else:
        ret = 0
        if all(s.count(i) > 0 for i in "753"):
            ret += 1
        for i in "753":
            ret += dfs(s+i)
    return ret

print(dfs("0"))

Solution (Python):
N = int(input())

def dfs(s):
    if int(s) > N:
        return 0
    ret = 0
    if all(s.count(c) > 0 for c in "753"):
        ret += 1
    for c in "753":
        ret += dfs(s + c)
    return ret

print(dfs("0"))

Solution (Python):


N = int(input())
def dfs(num, use):
    if num > N:
        return 0
    cnt = 1 if use == 0b111 else 0
    cnt += dfs(num*10 + 3, use | 0b001)
    cnt += dfs(num*10 + 5, use | 0b010)
    cnt += dfs(num*10 + 7, use | 0b100)
    return cnt
ans = dfs(0, 0)
print(ans)

Solution (Python):


N = int(input())
def dfs(num):
    if num > N:
        return 0
    flag = True
    for s in "357":
        if str(num).count(s) >= 1:
            pass
        else:
            flag = False
    ret = 1 if flag else 0

    for c in [3, 5, 7]:
        ret += dfs(num * 10 + c)
    return ret
ans = dfs(0)
print(ans)

Solution (Python):
n = int(input())

def dfs(s):
	if int(s) > n:
		
		return 0

	ret = 1 if all(s.count(c) > 0 for c in '753') else 0
	
	
	for c in '753':
		ret += dfs(s+c)
		
	return ret

print(dfs('0'))

Solution (Python):
from collections import defaultdict as dic

n = int(input())

data = [0] * 10000000
ans = 0

def judge_753(s):
    judge = 1
    flag = dic(int)
    for i in range(len(s)):
        if s[i] != '7' and s[i] != '5' and s[i] != '3':
            judge = 0
            break
        else:
            flag[int(s[i])] = 1

    if flag[3] != 1 or flag[5] != 1 or flag[7] != 1:
        judge = 0
    return judge

def search_num(num):
    ret = 0
    if num > n:
        return 0
    
    if judge_753(str(num)) == 1:
        ret += 1
    
    ret += search_num(num * 10 + 3) + search_num(num * 10 + 5) + search_num(num * 10 + 7)
    return ret


print(search_num(0))

Solution (Python):
N = int(input())
def dfs(s):
  if int(s) > N:
    return 0
  else:
    if all(s.count(c) > 0 for c in "753"):
      cnt = 1
    else:
      cnt = 0
    for c in "753":
      cnt += dfs(s+c)
    return cnt
print(dfs("0"))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

N = int(input())

def shichigosan(n):
    if n != '' and int(n) > N: 
        return 0
    return shichigosan(n+'3') + shichigosan(n+'5') + shichigosan(n+'7') + (1 if len(set(n)) == 3 else 0)

def main():
    print(shichigosan(''))

main()

Solution (Python):
from itertools import product
N = int(input())
S = []
for i in range(1, 10):
  S += list(product("753",repeat=i))
cnt = 0
for s in S:
  if int("".join(s)) > N:
    continue
  if all(s.count(c) > 0 for c in "753"):
    cnt += 1
print(cnt)

Solution (Python):



N = int(input())


def dfs(s):
    if int(s) > N:
        return 0
    if all(s.count(c) > 0 for c in '753'):
        ret = 1
    else:
        ret = 0
    for c in '753':
        ret += dfs(s + c)
    return ret


def main():

    print(dfs('0'))


if __name__ == "__main__":
    main()

Solution (Python):
n = 0
x = 0
multiplier = 0
result = 0

def solve():
	global x
	global n
	global multiplier
	global result
	
	if x>n:
		return
	if x>0:
		if str(3) in str(x) and str(5) in str(x) and str(7) in str(x):
			result+=1
	for i in range(3,8,2):
		x+=(i*(10**multiplier))
		multiplier+=1
		solve()
		multiplier-=1
		x-=(i*(10**multiplier))
	return

n = int(input())
solve()
print(result)

Solution (Python):
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

N = int(input())


def answer(info, ans):
    if max(ans) > N:
        return ans
    info2 = []
    for i in info:
        for l in ["3", "5", "7"]:
            info2.append(int(str(i) + l))
    ans += info2
    return answer(info2, ans)


a = sorted(list(set(answer([3, 5, 7], [3, 5, 7]))))
num = 0
for i in range(len(a)):
    if a[i] > N:
        print(num)
        break
    elif all(str(a[i]).count(d) > 0 for d in "753"):
        num += 1

Solution (Python):
N=int(input())
import queue
que=queue.Queue()
que.put(3);que.put(5);que.put(7)
num=[3,5,7]
cnt=0
while not que.empty():
    v=que.get()
    for n in num:
        nv=v*10+n
        if nv<=N:
            que.put(nv)
            nv_str=str(nv)
            if "3" in nv_str and "5" in nv_str and "7" in nv_str and len(set(nv_str))==3:
                cnt+=1
print(cnt)

Solution (Python):
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s + c)
    return ret

print(dfs('0'))

Solution (Python):
N = int(input())

def dfs(s:str):
    if int(s) > N: return 0
    
    cnt = 1 if all(s.count(c) > 0 for c in "753") else 0

    for c in "753":
        cnt += dfs(s + c)
    
    return cnt

print(dfs("0"))

Solution (Python):
def dfs(s, n):
    if int(s) > n:
        return 0

    cnt = 0
    if all(s.count(c) > 0 for c in '753'):
        cnt += 1

    for c in '753':
        cnt += dfs(s + c, n)

    return cnt

def main():
    n = int(input())

    print(dfs('0', n))

if __name__ == "__main__":
    main()

Solution (Python):
def f(i):
    global ans
    if i == l:
        if 3 in s and 5 in s and 7 in s:
            c = 0
            for j in range(l):
                c += s[j] * 10 ** (l - j - 1)
            if c <= n:
                ans += 1
                
        return
    f(i + 1)
    s[i] = 7
    f(i + 1)
    s[i] = 5
    f(i + 1)
    s[i] = 3

n = int(input())
l = len(str(n))
s = [3] * l
ans = 0
f(0)
m = [6, 36, 150, 540, 1806, 5796]
if l >= 4:
    for i in range(l - 3):
        ans += m[i]
print(ans)

Solution (Python):
n = int(input())
 
def dfs(s):

    if int(s) > n:
        return 0
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1
    else:
        cnt = 0
    cnt += dfs(s + '3')
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt
 
 
print(dfs('0'))

Solution (Python):
from itertools import product

n = int(input())

num_753 = []
for i in range(3, 10):
    for a in product(('7','5','3'), repeat=i):
        if a.count('7') > 0 and a.count('5') > 0 and a.count('3') > 0:
            num_753.append(int(''.join(a)))

num_753.sort()
for i, v in enumerate(num_753):
    if v > n:
        print(i)
        break
else:
    print(i+1)

Solution (Python):
from sys import stdin
from collections import deque
def main():
    
    readline=stdin.readline
    N=int(readline())

    
    count=0
    stack=deque(["0"])
    while len(stack)>=1:
        t=stack.pop()
        for s in "357":
            now=t+s
            if int(now)>N:
                break
            if ("7" in now) and ("5" in now) and ("3" in now):
                count+=1
            stack.append(now)
    
    print(count)

if __name__=="__main__":
    main()

Solution (Python):
N = int(input())

def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret


def main():
    print(dfs('0'))

if __name__ == "__main__":
    main()

Solution (Python):

N = int(input())

ans = 0
d = ['']
while d:
  base = d.pop()
  for c in '753':
    num = base + c
    if int(num) <= N and all(_c in num for _c in '753'):
      ans += 1
    
    if int(num) <= N:
      d.append(num)

print(ans)

Solution (Python):

N = int(input())

def solve(s):
  if int(s) > N:
    return 0
  res = 1 if all(s.count(c)>0 for c in '753') else 0 
  for c in '753':
    res += solve(s + c)
  return res

print(solve('0'))