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):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

ans = []
def dfs(a,m):
    global ans
    if len(a) == m:
        s = ""
        for i in range(m):
            s += str(a[i])
        if "7" in s and "5" in s and "3" in s:
            ans.append(int(s))
        return
    for i in [3,5,7]:
        a.append(i)
        dfs(a,m)
        a.pop()
if __name__ == "__main__":
    n = int(input())
    m = len(str(n))
    a = []
    for i in range(3,m+1):
        dfs(a,i)
    ans.sort()
    cnt = 0
    for i in range(len(ans)):
        if ans[i] <= n:
            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())
S = str(N)
l = len(S)


ans = 0


def dfs(n):
    global ans
    if len(str(n)) == l:
        if len(set(list(str(n)))) == 3 and n <= N:
            ans += 1
        return
    else:
        if len(set(list(str(n)))) == 3:
            ans += 1

    dfs(int(str(n) + "3"))
    dfs(int(str(n) + "5"))
    dfs(int(str(n) + "7"))


dfs(3)
dfs(5)
dfs(7)

print(ans)

Solution (Python):
import queue

n=int(input())

q=queue.Queue()

q.put(3)
q.put(5)
q.put(7)

c=0
num=q.get()
while num<=n:
    if "3" in str(num) and "5" in str(num) and "7" in str(num):
        c+=1
    q.put(num*10+3)
    q.put(num*10+5)
    q.put(num*10+7)
    num=q.get()

print(c)

Solution (Python):
N = input()

def dfs(A):
    if int(A) > int(N):
        return 0
    if all(A.count(c) for c in "753") >0:
        ans = 1
    else:
        ans = 0
        
    for i in "357":
        A += i
        ans += dfs(A)
        A = A[:-1]
        
    return ans

print(dfs("0"))

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

def saiki(s):
    global cnt,n
    L = ["3","5","7"]
    if eval(s) <= n:
        if len(set(s)) == 3:
            cnt += 1
        for i in L:
            saiki(s+i)

n = int(input())
cnt = 0
for i in ["3","5","7"]:
    saiki(i)
print(cnt)

Solution (Python):
N=int(input())
ans=set()
def saiki(A):
    if len(A)>0:
        B="".join(A)
        count=set(A)
        
        if eval(B)<=N:
            if len(count)==3:
                ans.add(B)
        else:
            return
    for i in [3,5,7]:
        A.append(str(i))
        saiki(A)
        A.pop()
saiki([])
print(len(ans))

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

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

    count = 0

    if "3" in s and "5" in s and "7" in s:
        count += 1
    
    for next_n in ["3", "5", "7"]:
        count += dfs(s + next_n)

    return count

print(dfs(""))

Solution (Python):
n = int(input())
def dfs(string):
    if len(string) == len(str(n)):
        return 1 if all(k in string for k in '753') and int(''.join(string)) <= n else 0

    rec = 0
    s = '753' if len(string) != 0 and string[-1] != '0' else '0753'
    for num in s:
        string.append(num)
        rec += dfs(string)
        string.pop()

    return rec

print(dfs([]))

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

def dfs(x, a, b, c):
    global ans
    if x > N:
        return
    if (a & b & c):
        ans += 1
    dfs(10 * x + 3, 1, b, c)
    dfs(10 * x + 5, a, 1, c)
    dfs(10 * x + 7, a, b, 1)

dfs(0, 0, 0, 0)
print(ans)

Solution (Python):
def calc(n):
  dic={0:0,1:3,2:5,3:7}
  ret=0
  for j in range(9):
    ret+=dic[n%4]*(10**j)
    n-=n%4
    n//=4
    if n==0:
      return ret

def check(n):
  cnt=[0]*10
  for c in str(n):
    cnt[int(c)]+=1
  if cnt[0]==0 and cnt[3]>=1 and cnt[5]>=1 and cnt[7]>=1:
    return True
  else:
    return False

n=int(input())
arr=[]
for i in range(4**9):
  tmp=calc(i)
  if check(tmp)==True:
    arr.append(tmp)
arr=sorted(arr)
for i in range(len(arr)):
  if arr[i]>n:
    print(i)
    break
else:
  print(len(arr))

Solution (Python):
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

ans = dfs("0")
print(ans)

Solution (Python):
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(input())

def F(list_):
    if list_ and int("".join(map(str, list_))) > N:
        return
    
    if 3 in list_ and 5 in list_ and 7 in list_:
        yield 1
    
    for v in [3, 5, 7]:
        list_.append(v)
        yield from F(list_)
        list_.pop()
    return

ans = sum(F([]))
print(ans)

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

def dfs(val, A):
    if val > n:
        return
    A.append(val)
    dfs(10 * val + 3, A)
    dfs(10 * val + 5, A)
    dfs(10 * val + 7, A)

A = []
dfs(3, A)
dfs(5, A)
dfs(7, A)

cnt = 0
for v in A:
    if len(set(list(str(v)))) == 3:
        cnt += 1
print(cnt)

Solution (Python):
cnt = 0

def main():
    n = int(input())
    m = len(str(n))
    nl = len(str(n))

    def cal(A):
        l = len(A) - 1
        ans = 0
        for idx, i in enumerate(A):
            ans += i*10**(l - idx)
        return ans

    def dfs(A):
        global cnt
        if len(A) == m:
            if len(list(set(A) & set([3, 5, 7]))) == 3:
                if (cal(A)) <= n:
                    
                    cnt += 1
            return
        for i in (3, 5, 7):
            A.append(i)
            dfs(A)
            A.pop()
    for m in range(nl+1):
         dfs([])
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
num=input()
count = 0
for i in range(3, len(num) + 1):
  for j in itertools.product([3,5,7], repeat=i):
    sumj = 0
    for k in range(i):
      sumj += j[k] * (10 ** (i-k-1))
    
    if '3' in (str)(sumj) and '5' in (str)(sumj) and '7' in (str)(sumj):
      if sumj <= (int)(num):
        count += 1
        
      else:
        break
print(count)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint


INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()


def base10to(n,b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)


def base10from(num, b):
    n = 0
    numlist = list(num);
    while (numlist):
        n *= b
        n += int(numlist.pop(0))
    return n

count = 0

for i in range(3,10):
    m = 3**i
    for j in range(m):
        s = list(base10to(j,3))
        a = "".join(s)
        b = a.zfill(i)
        c = list(b)
        for k in range(i):
            if c[k]=="0":
                c[k] = "3"
            elif c[k]=="1":
                c[k] = "5"
            elif c[k]=="2":
                c[k] = "7"
            else:
                print("E")
        d = "".join(c)
        e = int(d)
        if e<=n:
            if len(set(c))==3:
                count += 1
            else:
                pass
        else:
            print(count)
            exit()

print(count)
exit()

Solution (Python):
from itertools import product
from bisect import bisect_left, bisect_right

n = int(input())
s = []
for i in range(3, 10):
    for v in product('753', repeat=i):
        if len(set(v)) >= 3:
            s.append(int(''.join(v)))

s.sort()

idx = bisect_right(s, n)
print(len(s[:idx]))

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

Solution (Python):
def cal(N,n_str):
    n_list = ["7","5","3"]

    if len(n_str) != 0:
        if int(n_str) <= N:
            if len(n_str) == len(str(N)) and len(set(list(n_str))) == 3:
                return 1
            elif len(n_str) == len(str(N)) and len(set(list(n_str))) < 3:
                return 0
            elif len(n_str) < len(str(N)) and len(set(list(n_str))) == 3:
                return 1 + cal(N,n_str+"7") + cal(N,n_str+"5") + cal(N,n_str+"3")
            elif len(n_str) < len(str(N)) and len(set(list(n_str))) < 3:
                return cal(N,n_str+"7") + cal(N,n_str+"5") + cal(N,n_str+"3")
        else:
            return 0
    else:
        return cal(N,n_str+"7") + cal(N,n_str+"5") + cal(N,n_str+"3")

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

    print(cal(N,""))

if __name__ == "__main__":
    main()

Solution (Python):
n = input()
t = ["3","5","7"]
for i in range(8):
    s = []
    for j in t:
        s.append(j+"3")
        s.append(j+"5")
        s.append(j+"7")
    t += s
t = set(t)
t = list(t)
t.sort()
count = 0
for i in range(len(t)):
    if len(t[i]) > len(n):
        continue
    if int(t[i]) > int(n):
        continue
    if '3' in t[i] and '5' in t[i] and '7' in t[i]:
        count+=1
print(count)

Solution (Python):
from collections import deque

n = int(input())
q = deque(['3','5','7'])
ans = 0
l = []
while True:
    v = q.popleft()
    if int(v) >= n:
        if int(v) == n and ('3' in v and '5' in v and '7' in v):
            ans += 1
        print(ans)
        exit() 
    if '3' in v and '5' in v and '7' in v:
        ans += 1
        l.append(int(v))
    q.append(v+'3')
    q.append(v+'5')
    q.append(v+'7')

Solution (Python):
import itertools
N=int(input())
ans=0
S=[]
for i in range(10):
    S+=list(itertools.product("357",repeat=i))
for s in S:
    if len(set(s))>2 and int("".join(s))<=N:
        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 bisect
n = int(input())
l = len(str(n))
ary = []
siti = ["3","5","7"]
def dfs (s,t):
  if len(s) == t:
    if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
      ary.append(int(s))
    return
  for j in siti:
    dfs(s+j,t)
for i in range(3,l+1):
  dfs("",i)
print (bisect.bisect_right(ary,n))

Solution (Python):
import bisect
n = int(input())
l = len(str(n))
ary = []
siti = ["3","5","7"]
def dfs (s,t):
	if len(s) == t:
		if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
			ary.append(int(s))
		return
	for j in siti:
		dfs(s+j,t)
for i in range(3,l+1):
	dfs("",i)

print (bisect.bisect_right(ary,n))

Solution (Python):
import bisect
n = int(input())
l = len(str(n))
ary = []
siti = ["3","5","7"]
def dfs (s,t):
	if len(s) == t:
		if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
			ary.append(int(s))
		return
	for j in siti:
		dfs(s+j,t)
for i in range(3,l+1):
	dfs("",i)

print (bisect.bisect_right(ary,n))

Solution (Python):
import bisect
n = int(input())
l = len(str(n))

ary = []

siti = ["3","5","7"]
def dfs (s,t):
	if len(s) == t:
		if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
			ary.append(int(s))
		return
	for j in siti:
		dfs(s+j,t)

for i in range(3,l+1):
	dfs("",i)

ary.sort()
print (bisect.bisect_right(ary,n))

Solution (Python):
import itertools

n = input()
ans = 0
l = ["3", "5", "7"]

for i in range(3, len(n) + 1):
    for j in itertools.product(l, repeat = i):
        j = "".join(j)
        if int(j) <= int(n):
            if "3" in str(j):
                if "5" in str(j):
                    if "7" in str(j):
                        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):
n = int(input())
def dfs(sss):
  if(int(sss) > n):
    return 0
  r = 1 if(all(sss.count(c) > 0 for c in '753')) else 0
  for c in '357':
    r += dfs(sss+c)
  return r
print(dfs('0'))

Solution (Python):
def dfs(n):
    if int(n)>N:
        return
    L.append(int(n))
    dfs(n+"3")
    dfs(n+"5")
    dfs(n+"7")
    
N=int(input())
L=[]
dfs("3")
dfs("5")
dfs("7")

M=[]
for l in L:
    S=str(l)
    if "3" in S and "5" in S and "7" in S and l<=N:
        M.append(l)
print(len(M))

Solution (Python):
import sys
from io import StringIO
import unittest


def recursive(base, pattern, n):

    for i in ["7", "5", "3"]:

        new_target = "".join(base + str(i))

        
        if int(new_target) > n:
            continue

        
        if new_target.count("7") >= 1 and new_target.count("5") >= 1 and new_target.count("3") >= 1:
            pattern.append(new_target)

        recursive(new_target, pattern, n)


def resolve():

    n = int(input())

    pattern = []

    
    for i in ["7", "5", "3"]:
        recursive(i, pattern, n)

    print(len(pattern))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """575"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3600"""
        output = """13"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """999999999"""
        output = """26484"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

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 itertools import product
n = int(input())
cnt = 0
a = ['7', '5', '3']
for i in range(3, len(str(n)) + 1):
    for j in product(a, repeat=i):
        word = ''.join(j)
        if all(w in word for w in ['7', '5', '3']) and int(word) <= n:
            cnt += 1
print(cnt)

Solution (Python):


n = int(input())


stack = [0] 
pre_ans = [] 

while stack: 
    tmp = stack.pop() 
    if tmp <= n: 
        pre_ans.append(tmp) 
        x = tmp * 10 + 3 
        y = tmp * 10 + 5 
        z = tmp * 10 + 7 
        stack += [x, y, z]  


ans = 0
for i in pre_ans: 
    if len(set(str(i))) == 3:
        ans += 1

print(ans)


'''
上記は パターンを列挙 → 全探索 だが、
実際には パターンを列挙 しながら 探索 が高効率

n = int(input())

stack = [0]
ans = 0
while stack:
    tmp = stack.pop()
    if tmp <= n:
        if len(set(str(tmp))) == 3:
            ans += 1
        x = tmp * 10 + 3
        y = tmp * 10 + 5
        z = tmp * 10 + 7
        stack += [x, y, z]

print(ans)

'''

Solution (Python):


from collections import deque

n = int(input())


queue = deque([0]) 
pre_ans = [] 

while queue: 
    tmp = queue.popleft() 
    if tmp <= n: 
        pre_ans.append(tmp) 
        x = tmp * 10 + 3 
        y = tmp * 10 + 5 
        z = tmp * 10 + 7 
        queue += [x, y, z]  


ans = 0
for i in pre_ans: 
    if len(set(str(i))) == 3:
        ans += 1

print(ans)

'''
上記は パターンを列挙 → 全探索 だが、
実際には パターンを列挙 しながら 探索 が高効率

from collections import deque

n = int(input())


queue = deque([0]) 

ans = 0
while queue: 
    tmp = queue.popleft() 
    if tmp <= n: 
        if len(set(str(tmp))) == 3: 
            ans += 1
        x = tmp * 10 + 3 
        y = tmp * 10 + 5 
        z = tmp * 10 + 7 
        queue += [x, y, z]  

print(ans)

'''

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)


from collections import Counter,deque,defaultdict





n=n0()

d=deque([3,5,7])
ans=0
while True:
    a=d.popleft()
    if a>n:
        break
    else:
        s=str(a)
        if s.count("3")>0 and s.count("5")>0 and s.count("7")>0:
            ans+=1
        d.append(10*a+3)
        d.append(10*a+5)
        d.append(10*a+7)
print(ans)

Solution (Python):
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


n=int(input())
stack=[0]
ans=0
while stack:
    q=stack.pop()
    if q<=n:
        if len(set(str(q)))==3:
            ans+=1
        stack.append(q*10+3)
        stack.append(q*10+5)
        stack.append(q*10+7)
print(ans)

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

stack = [0]
ans = 0
while stack:
    tmp = stack.pop()
    if tmp <= n:
        if len(set(str(tmp))) == 3:
            ans += 1
        stack += [tmp * 10 + 3, tmp * 10 + 5, tmp * 10 + 7]

print(ans)

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

stack = [0]
ans = 0
while stack:
    tmp = stack.pop()
    if tmp <= n:
        if len(set(str(tmp))) == 3:
            ans += 1
        x = tmp * 10 + 3
        y = tmp * 10 + 5
        z = tmp * 10 + 7
        stack += [x, y, z]

print(ans)

Solution (Python):


n = int(input())


stack = [0] 
pre_ans = [] 

while stack: 
    tmp = stack.pop() 
    if tmp <= n: 
        pre_ans.append(tmp) 
        x = tmp * 10 + 3 
        y = tmp * 10 + 5 
        z = tmp * 10 + 7 
        stack += [x, y, z]  


ans = 0
for i in pre_ans: 
    if len(set(str(i))) == 3:
        ans += 1

print(ans)

Solution (Python):
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

MAX_LIM = 10**9
N = (input())
keta = len(N)
N = int(N)


keta_lis = {1: [3, 5, 7], 2: [], 3: [],
            4: [], 5: [], 6: [], 7: [], 8: [], 9: []}
for i in range(1, keta):
    times = pow(10, i)
    for tmp in keta_lis[i]:
        for num in [3, 5, 7]:
            keta_lis[i+1].append(tmp + times*num)
ans = []
for keta in keta_lis.keys():
    ans.extend(keta_lis[keta])
ans = np.array(sorted(ans))
ans = ans[357 <= ans]
ans = ans[ans <= N]
count = 0
for ans_ in ans:
    if (('3' in str(ans_)) and ('5' in str(ans_)) and ('7' in str(ans_))):
        
        count += 1
print(count)

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

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

  return res

print(dfs("0"))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 

cnt = 0
def include(x):
    global cnt
    s = str(x)
    if ('3' in s) and ('5' in s) and ('7' in s):
        cnt += 1  
     
def main():
    n = int(readline())
    dq = deque()
    dq.append(0)
    cnd = [0]
    dd = (3, 5, 7)
    while len(dq)>0:
        v = dq.popleft()
        for i in dd:
            if v*10+i>n:
                continue
            dq.append(v*10+i)
            cnd.append(v*10+i)
            include(v*10+i)
        if cnd[-1] > n:
            break
    print(cnt)
if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product
l = []
for _ in range(3,10):
    tmp = list(product('753', repeat = _))
    l += tmp

m = []
for i in l:
    if len(set(i)) == 3:
       m.append(int(''.join(i)))

n = int(input())
ans = 0
for j in m:
    if j <= n:
        ans += 1

print(ans)

Solution (Python):
from collections import Counter
N = int(input())

def change_to_num(ls):
    ls = list(map(str, ls))
    strnum = ''.join(ls)
    return int(strnum)
def dfs(num_ls):
    '''
    引数のnum_ls以降の753numの総数を返す
    '''
    if change_to_num(num_ls) > N:
        return 0
    
    tmp = 0
    
    c = Counter(num_ls)
    is753 = True
    for num in [7,5,3]:
        if c[num] == 0:
            is753 = False
    if is753:
        tmp += 1
    
    
    for num in [7,5,3]:
        num_ls.append(num)
        tmp += dfs(num_ls)
        num_ls.pop()
    return tmp
print(dfs([0]))

Solution (Python):
N = int(input())
import itertools
cnt = 0
for i in range(1,10):
    Ls = list(itertools.product(["3","5","7"], repeat=i))
    for L in Ls:
        if ("3" in L) and ("5" in L) and ("7" in L):
            S = int("".join(L))
            if S<=N:
                cnt+=1
print(cnt)

Solution (Python):
n= int(input())
def func(cur,use,count):
  if cur > n:
    return
  if use == 0b111:
    count.append(1)
  func(cur*10+3,use|0b001,count)
  func(cur*10+5,use|0b010,count)
  func(cur*10+7,use|0b100,count)
res = []
func(0,0,res)
print(sum(res))

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

from itertools import product

l = []
for i in range(3, 10):
    for prod in product(*[['3', '5', '7'] for _ in range(i)]):
        p = ''.join(list(prod))
        if p.count('3') and p.count('5') and p.count('7'):
            l.append(p)

ans = 0
for ll in l:
    if int(ll) <= n:
        ans += 1
print(ans)

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





l=[7,5,3]
count=0

def dfs(cur,use):
    global count
    if cur>n:
        return
    if use==0b111 :
        count+=1
    dfs(cur*10+3,use | 0b001)
    dfs(cur*10+5,use | 0b010)
    dfs(cur*10+7,use | 0b100)

dfs(0,0b000)
print(count)

Solution (Python):
import sys
readline = sys.stdin.readline

N = int(readline())

stack = [3,5,7]
ans = 0

all = {"3","5","7"}
def isOk(x):
  return len(all - set(str(x))) == 0
  
while stack:
  num = stack.pop()
  if num > N:
    continue
  if isOk(num):
    ans += 1
  for i in (3,5,7):
    stack.append(num * 10 + i)
  
print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline

N = int(readline())

stack = [3,5,7]
ans = 0

def isOk(x):
  s = str(x)
  for c in "357":
    if c not in s:
      return False
  return True
  
while stack:
  num = stack.pop()
  if num > N:
    continue
  if isOk(num):
    ans += 1
  for i in (3,5,7):
    stack.append(num * 10 + i)
  
print(ans)

Solution (Python):
def dfs(L):
    global N, ans
    ret = 0
    if all([L.count(i) for i in ["3", "5", "7"]]):
        ret += 1
    for j in ["3", "5", "7"]:
        if int(L + j) <= int(N):
            ret += dfs(L + j)
    return ret

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

Solution (Python):
MAX_DIGIT = 9

n = int(input())

def n753():
    q = ['']
    ns = []
    while q:
        n = q.pop()
        for c in ('7', '5', '3'):
            n1 = n + c
            if len(n1) <= MAX_DIGIT:
                q.append(n1)
                ns.append(n1)
    ns = [int(n) for n in ns if len(set(n)) == 3]
    return ns


answer = sum(1 for n1 in n753() if n1 <= n)
print(answer)

Solution (Python):
n = int(input())
ans=0
def dfs(A):
    global ans
    
    if A and int(''.join(A)) > n:
        return
    
    if not (set(A) ^ set('357')):
        ans+=1
    for v in '357':
        A.append(v)
        dfs(A)
        A.pop()
dfs([])
print(ans)

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


def se(x):
    for i in range(3 ** x):
        r = ""
        for _ in range(x):
            r += "753"[i % 3]
            i //= 3
        if "7" in r and "5" in r and "3" in r:
            yield int(r)


ans = 0
for i in range(9):
    for j in se(i + 1):
        if j <= n:
            ans += 1
print(ans)

Solution (Python):
N = [int(x) for x in list(input())] 

def dfs(L):
    global N
    if len(L) == len(N):
        if L <= N and L.count(7) > 0 and L.count(5) > 0 and L.count(3) > 0:
            return 1
        else:
            return 0

    ans = 0
    if len(L) == 0 or L[-1] == 0:
        ans += dfs(L + [0])
    for j in [3, 5, 7]:
        ans += dfs(L + [j])
    return ans

print(dfs([]))

Solution (Python):
n = int(input())
def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all( (i in s) for i in '753') else 0
    for i in '753':
        ret += dfs(s+i)
    return ret
print(dfs('0'))

Solution (Python):
N = [0] + [int(x) for x in list(input())] 

def dfs(L, same):
    '''same ... True if L[i] == N[i] for all i = 0, 1, ..., len(L)-1'''
    global N
    if len(L) == len(N):
        if L.count(7) > 0 and L.count(5) > 0 and L.count(3) > 0:
            return 1
        else:
            return 0

    i = len(L) - 1  
    ans = 0
    if same:    
        if i == 0:  
            next = [0, 3, 5, 7]
        else:
            next = [3, 5, 7]
        for j in next:
            if j < N[i + 1]:
                ans += dfs(L + [j], same = False)
            if j == N[i + 1]:
                ans += dfs(L + [j], same = True)
    else:  
        if L[i] == 0: 
            next = [0, 3, 5, 7]
        else:
            next = [3, 5, 7]
        for j in next:
            ans += dfs(L + [j], same = False)

    return ans

print(dfs([0], True))

Solution (Python):
n = int(input())
count = 0
stack = [0]
def check(n):
  s = str(n)
  if "3" in s and "5" in s and "7" in s:
    return True
  else:
    return False
while len(stack)>0:
  now = stack.pop()
  if check(now) and now <= n:
    count += 1
  if now < n:
    stack.append(now*10+3)
    stack.append(now*10+5)
    stack.append(now*10+7)
print(count)

Solution (Python):

import sys
input = sys.stdin.readline






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
    for c in "753":
        cnt += dfs(s + c)
    return cnt
    




N = int(input())

print(dfs("0"))

Solution (Python):
import itertools
from collections import deque
N=int(input())
tp=("3","5","7")

ans=0
for j in itertools.product(tp, repeat=3):
    q=deque()
    q.append(''.join(j))
    while(len(q)>0):
        pos=q.popleft()
        
        if int(pos)<=N and all([ True if k in pos else False for k in tp]):
            ans+=1
        if len(pos)<len(str(N)):
            for i in tp:
                q.append(i+pos)
print(ans)

Solution (Python):
N = int(input())
global cnt
cnt = 0

def dfs(x, use):
    global cnt
    if x > N:
        return
    if use == 7:
        cnt += 1
    dfs(x*10+3, use|0b001)
    dfs(x*10+5, use|0b010)
    dfs(x*10+7, use|0b100)


dfs(0, 0)
print(cnt)

Solution (Python):
n = int(input())
def DFS(s):
    if int(s)>n:
        return 0
    tmp = 1 if all(s.count(c) for c in '753') else 0
    for c in '753':
        tmp += DFS(s+c)
    return tmp
print(DFS('0'))

Solution (Python):
n = input()
dp = [[0]*8 for _ in range(2)]
if int(n[0])==3:
    dp[0][4] = 1
if int(n[0])==5:
    dp[0][2] = 1
if int(n[0])==7:
    dp[0][1] = 1
if int(n[0])>3:
    dp[1][4] = 1
if int(n[0])>5:
    dp[1][2] = 1
if int(n[0])>7:
    dp[1][1] = 1
for i in range(1, len(n)):
    newdp = [[0]*8 for _ in range(2)]
    if n[i]=='3':
        newdp[0][4] = dp[0][4]
        newdp[0][5] = dp[0][1] + dp[0][5]
        newdp[0][6] = dp[0][2] + dp[0][6]
        newdp[0][7] = dp[0][3] + dp[0][7]
    elif n[i]=='5':
        newdp[0][2] = dp[0][2]
        newdp[0][3] = dp[0][1] + dp[0][3]
        newdp[0][6] = dp[0][4] + dp[0][6]
        newdp[0][7] = dp[0][5] + dp[0][7]
    elif n[i]=='7':
        newdp[0][1] = dp[0][1]
        newdp[0][3] = dp[0][2] + dp[0][3]
        newdp[0][5] = dp[0][4] + dp[0][5]
        newdp[0][7] = dp[0][6] + dp[0][7]
    newdp[1][1] = dp[1][1] + dp[0][1]*(int(n[i])>7) + 1
    newdp[1][2] = dp[1][2] + dp[0][2]*(int(n[i])>5) + 1
    newdp[1][4] = dp[1][4] + dp[0][4]*(int(n[i])>3) + 1
    newdp[1][3] = dp[1][1] + dp[1][2] + dp[1][3]*2 + (dp[0][1] + dp[0][3])*(int(n[i])>5) + (dp[0][2] + dp[0][3])*(int(n[i])>7)
    newdp[1][5] = dp[1][1] + dp[1][4] + dp[1][5]*2 + (dp[0][1] + dp[0][5])*(int(n[i])>3) + (dp[0][4] + dp[0][5])*(int(n[i])>7)
    newdp[1][6] = dp[1][2] + dp[1][4] + dp[1][6]*2 + (dp[0][2] + dp[0][6])*(int(n[i])>3) + (dp[0][4] + dp[0][6])*(int(n[i])>5)
    newdp[1][7] = dp[1][3] + dp[1][5] + dp[1][6] + dp[1][7]*3 + (dp[0][3]+ dp[0][7])*(int(n[i])>3) + (dp[0][5]+ dp[0][7])*(int(n[i])>5) + (dp[0][6]+ dp[0][7])*(int(n[i])>7)
    dp = newdp
print(dp[0][7]+dp[1][7])

Solution (Python):
from itertools import product


N = int(input())


if N < 357:
    print(0)
else:
    max_dig = len(str(N))
    dig = 3
    sgs_nuns = []
    sgs = {"7", "5", "3"}
    str_join = "".join
    for n in range(3, max_dig + 1):
        sgs_nuns += [
            str_join(n)
            for n in product(["7", "5", "3"], repeat=n)
            if set(str_join(n)) == sgs and int(str_join(n)) <= N
        ]

    cnt = len(sgs_nuns)
    print(cnt)

Solution (Python):
from itertools import product

n = int(input())

L=[]
for i in range(3,10):
    L+=list(product("753",repeat=i))

ans = 0
for l in L:
    if len(set(l)) == 3 and int("".join(l)) <= n:
        ans += 1

print(ans)