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 math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()

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 math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
ans = 0
for x in product([0, 3, 5, 7], repeat=9):
    y = 0
    for i in range(9):
        y += x[8-i] * 10**i
    if y > n:
        break
    if str(y).count('0') == 0 and x.count(3) > 0 and x.count(5) > 0 and x.count(7) > 0:
        ans += 1
print(ans)

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


queue = deque(['3', '5', '7'])

ans = set([])
while queue:
    now_nums = queue.popleft()
    if now_nums in ans or int(now_nums) > N:
        continue
    if len(now_nums) >= 3 and '3' in now_nums and '5' in now_nums and '7' in now_nums:
        ans.add(now_nums)
    for next_num in ['3', '5', '7']:
        if int(now_nums + next_num) > N:
            continue
        queue.append(now_nums + next_num)
print(len(ans))

Solution (Python):
N = int(input())
Count = 0
if N>=357:
    Flag = True
    Now = ['33','35','37','53','55','57','73','75','77']
    TFS = ['3','5','7']
    Nex = []
    while int(Now[-1])<=N:
        for TNow in Now:
            for TTFS in TFS:
                Nex.append(TNow+TTFS)  
        for TNex in Nex:
            if all(TNex.count(C)>0 for C in '357') and int(TNex)<=N:
                Count += 1
        Now = Nex
        Nex = []
print(Count)

Solution (Python):
from itertools import product
n=int(input())
tmp=2
ans=0
Flag=True
while Flag:
    tmp+=1
    iterator=product(range(3),repeat=tmp)
    for idxs in iterator:
        num=''.join(map(str,idxs))
        num753=str(num).replace('0', '3').replace('1', '5').replace('2', '7')
        if '7' in num753 and '5' in num753 and '3' in num753:
            if int(num753)<=n:
                ans+=1
            else:
                Flag=False
                break
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
ma = len(str(n))

ans = 0
def dfs(stack):
    global ans
    if len(stack) > ma:
        return
    if len(stack) >= 3:
        num = int(''.join(map(str, stack)))
        if stack.count(3) and stack.count(5) and stack.count(7) and num <= n:
            ans += 1
    for i in [3,5,7]:
        stack.append(i)
        dfs(stack)
        stack.pop(-1)
    return ans

stack = []
print(dfs(stack))

Solution (Python):
from itertools import product
n=int(input())
ans=[]
lst=[3,5,7]
for i in range(3,10):
    for v in product(lst,repeat=i):
        if len(set(v))==3:
            ans.append(int("".join(map(str,v))))
answer=0
for i in ans:
    if i<=n:
        answer+=1
print(answer)

Solution (Python):
import itertools
n=int(input())
sm=0
l=["3","5","7"]
for i in range(3,len(str(n))+1):
  b=list(itertools.product(l, repeat=i))
  for m in b:
    s="".join(m)
    if int(s)<=n and "7" in s and "3" in s and "5" in s:sm+=1
       
print(sm)

Solution (Python):
n = int(input())
keta = len(str(n))

if keta <= 2:
    print(0)
else:
    
    ans = 0
    for k in range(3, keta):
        ans += pow(3, k) - 3 - (3*(pow(2, k) - 2))

    from itertools import product
    for l in product(['3', '5', '7'], repeat=keta):
        if not '3' in l or not '5' in l or not '7' in l:
            continue
        nn = int(''.join(l))
        if nn <= n:
            ans += 1

    print(ans)

Solution (Python):
n = int(input())
keta = len(str(n))

if keta <= 2:
    print(0)
else:
    
    ans = 0
    
    

    from itertools import product
    for k in range(3, keta+1):
        for l in product(['3', '5', '7'], repeat=k):
            if not '3' in l or not '5' in l or not '7' in l:
                continue
            nn = int(''.join(l))
            if nn <= n:
                ans += 1

    print(ans)

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

Solution (Python):
N=input()
l=len(N)
N=int(N)
if l<3:
    print(0)
else:
    
    cands=[None]*(l+1)
    cands[0]={}
    cands[1]={}
    cands[2]={}
    cands[3]= {"357","375","537","573","735","753"}
    
    for i in range(3,l):
        cands[i+1] = set(s+c for c in cands[i] for s in ["3","5","7"]) | set(c+s for c in cands[i] for s in ["3","5","7"] )
        cands[i+1].add("3"+"5"*(i-1)+"7")
        cands[i+1].add("3"+"7"*(i-1)+"5")
        cands[i+1].add("5"+"3"*(i-1)+"7")
        cands[i+1].add("5"+"7"*(i-1)+"3")
        cands[i+1].add("7"+"3"*(i-1)+"5")
        cands[i+1].add("7"+"5"*(i-1)+"3")
    
    ans=sum( [len(cands[i]) for i in range(l)] )
    ans+=sum( int(c)<=N for c in cands[l])
    print(ans)

Solution (Python):
def dfs(A):
    x ="".join(A)
    if 3 <=len(A) :
        
        if int(x) <=N :
            if x.count("3") >=1 and x.count("5") >=1 and x.count("7") >=1:
                c.append(int(x))
    if len(x) ==len(str(N)): 
        return

    for i in ["3","5","7"] :
        A.append(i)
        dfs(A)
        A.pop()
 
N = int(input())
c =[]
a =dfs([])
print(len(c))

Solution (Python):
import itertools

n = int(input())

a =["3","5","7"]
l = []
for i in range(3,10):
    for j in itertools.product(a,repeat=i):
        l.append(j)

ans = 0
for i in l:
    if int("".join(i)) <= n and i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1:
        ans += 1

print(ans)

Solution (Python):
n=int(input())
li = ["357","375","537","573","753","735"]
if n<1000:
  li=[s for s in li if int(s)<=n]
  print(len(li))
  exit()
t=["7","5","3"]
ans = 6
for i in range(4,10):
  li_new = []
  for s in li:
    for j in range(i):
      for k in t:
        u=int(s[:j]+k+s[j:])
        if u<=n:
          li_new.append(str(u))
  li=list(set(li_new))
  ans += len(li)
print(ans)

Solution (Python):
import itertools
N = int(input())
A = ["3", "5", "7"]
L = []
for i in range(1, 10):
  for l in itertools.product(A, repeat=i):
    L.append(l)
c = 0
for l in L:
  if int("".join(l))<=N and l.count("3")>=1 and \
  l.count("5")>=1 and l.count("7")>=1:
    c += 1
print(c)

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

s="0"
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="0"
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
import bisect

N = int(input())
L = []

for i in range(3, 10):
  for A in product(["3", "5", "7"], repeat = i):
    if len(set(A)) == 3:
      x = int("".join(A))
      L.append(x)

ans = bisect.bisect(L, N)

print(ans)

Solution (Python):
import collections

L = [3,5,7]
Q = collections.deque(L)
A = []


for i in range (0, 40000):
	V = Q.popleft()
	A.append(V)
	Q.append(V*10+3)
	Q.append(V*10+5)
	Q.append(V*10+7)

import bisect

D = []

for i in range (0, 40000):
	V = str(A[i])
	if V.count('3') > 0 and V.count('5') > 0 and V.count('7') > 0:
		D.append(int(V))

N = int(input())
print(bisect.bisect_right(D, N))

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

list = [[3,5,7]]

for i in range(9):
    new =[]
    for j in list[-1]:
        new.append(10*j+3)
        new.append(10*j+5)
        new.append(10*j+7)
    list.append(new)

a_list=[]
ans =0
for i in list:
    for j in i:
        if N <j:
            print(ans)
            exit()
        if '3' in str(j) and '5' in str(j) and '7' in str(j):
            ans += 1

Solution (Python):

import sys
sys.setrecursionlimit(10**6)

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

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

Solution (Python):

import sys



from itertools import product
N =input().strip()
N_int =int(N)
count =0
for i in range(3,len(N)+1):
    for tt in product(["3","5","7"], repeat=i):
        t ="".join(tt)
        if t.count("3") >=1 and t.count("5") >=1 and t.count("7") >=1 and int(t) <=N_int:
            count +=1
            
print(count)

Solution (Python):

n = int(input())

def depth_first_search(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 += depth_first_search(s + c)
        
    return ret

print(depth_first_search('0'))

Solution (Python):
from collections import deque,Counter
n=int(input())
if n<357:
    print(0)
    exit()
ans=0
num753=deque()
num753.append('3')
num753.append('5')
num753.append('7')
while len(num753)!=0:
    tmp=num753.popleft()
    cou=Counter(list(tmp))
    if len(tmp)>=3 and int(tmp)<=n and len(cou)==3:
        ans+=1
        num753.append(tmp+'3')
        num753.append(tmp+'5')
        num753.append(tmp+'7')
    elif int(tmp)<=n:
        num753.append(tmp+'3')
        num753.append(tmp+'5')
        num753.append(tmp+'7')
print(ans)

Solution (Python):
from collections import deque

N = int(input())

def bfs(s):
    que = deque()
    que.append(s)
    cnt = 0
    while que.__len__() != 0:
        s = que.popleft()
        for ds in '753':
            ss = s + ds
            if int(ss) > N:
                continue
            if all(ss.count(i) > 0 for i in '753'):
                cnt += 1
            que.append(ss)
    return cnt

ans = 0
ans += bfs('3')
ans += bfs('5')
ans += bfs('7')

print(ans)

Solution (Python):
from collections import deque

N = int(input())

def bfs(s):
    que = deque()
    que.append(s)
    cnt = 0
    while que.__len__() != 0:
        s = que.popleft()
        for ds in '753':
            ss = s + ds
            if int(ss) > N:
                continue
            if all(ss.count(i) > 0 for i in '753'):
                cnt += 1
            que.append(ss)
    return cnt

ans = 0
ans += bfs('3')
ans += bfs('5')
ans += bfs('7')

print(ans)

Solution (Python):
import math
from bisect import bisect_right
from copy import copy
n = int(input())
li = set([357,375,537,573,735,753])
li2 = set()
for i in li:
    li2.add(str(i))
li4 = copy(li2)
for k in range(6):
    li3 = set()
    for i in li4:
        for j in range(len(i)):
            i1 = i[:j]+'3' +i[j:]
            i2 = i[:j]+'5' +i[j:]
            i3 = i[:j]+'7' +i[j:]
            li3.add(i1)
            li3.add(i2)
            li3.add(i3)
    li4 = copy(li3)
    for j in li4:
        li2.add(j)
li5 = []
for i in li2:
    li5.append(int(i))
li5.sort()
k = bisect_right(li5, n)
print(k)

Solution (Python):
import math
from bisect import bisect_right
from copy import copy
n = int(input())
li = set([357,375,537,573,735,753])
li2 = set()
for i in li:
    li2.add(str(i))
li4 = copy(li2)
for k in range(6):
    li3 = set()
    for i in li4:
        for j in range(len(i)):
            i1 = i[:j]+'3' +i[j:]
            i2 = i[:j]+'5' +i[j:]
            i3 = i[:j]+'7' +i[j:]
            li3.add(i1)
            li3.add(i2)
            li3.add(i3)
    li4 = copy(li3)
    for j in li4:
        li2.add(j)
li5 = []
for i in li2:
    li5.append(int(i))
li5.sort()
k = bisect_right(li5, n)
print(k)

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]

ans = 0

def main():
    N = NI()

    def dfs(num):
        global ans
        if "3" in str(num) and "5" in str(num) and "7" in str(num):
            ans += 1
        if num * 10 + 3 <= N:
            dfs(num * 10 + 3)
        if num * 10 + 5 <= N:
            dfs(num * 10 + 5)
        if num * 10 + 7 <= N:
            dfs(num * 10 + 7)

    dfs(0)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
from itertools import product
target = ['3','5','7']

n=int(input())
tmp=n
keta=0
while tmp!=0:
  tmp//=10
  keta+=1
check_list = []
for i in range(1,keta+1):
  tmp=[]
  for _ in range(i):
    tmp.append(target.copy())
    tmp_product = list(product(*tmp))
  check_list+=[int(''.join(nums)) for nums in tmp_product]
check_list = sorted(check_list)

cnt=0
for i in check_list:
  if i <= n:
    tmp = set([w for w in str(i)])
    if len(tmp)==3:
      cnt+=1
  else:
    break
print(cnt)

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


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

Solution (Python):
from itertools import product
N = int(input())

keta = len(str(N))


count=0
for i in range(3,keta+1):
    a = ["7","5","3"]
    As = list(product((a), repeat=i))
    for A in As:
        
        if ("3" in A) and ("5" in A) and ("7" in A):
            S = int("".join(A))
            if S <=N:
                count+=1

print(count)

Solution (Python):
N = int(input())
L = []


def f(v: str):
    for i in list('357'):
        new_v = v + i
        if N < int(new_v):
            continue
        if new_v.count('3') >= 1 and new_v.count('5') >= 1 and new_v.count(
                '7') >= 1:
            L.append(new_v)
        f(new_v)


f('')

ans = len(L)
print(ans)

Solution (Python):
from collections import deque

def check753(num):
    three = False
    five = False
    seven = False
    for s in num:
        if s == "3":
            three = True
        elif s == "5":
            five = True
        elif s == "7":
            seven = True
        if three and five and seven:
            return True
    return False

n = int(input())

q = deque([3,5,7])

ans = 0
while q:
    now = q.popleft()
    
    t = "".join([str(now), "3"])
    if int(t) <= n:
        q.append(int(t))
        if check753(t):
            ans += 1
    f = "".join([str(now), "5"])
    if int(f) <= n:
        q.append(int(f))
        if check753(f):
            ans += 1
    s = "".join([str(now), "7"])
    if int(s) <= n:
        q.append(s)
        if check753(s):
            ans += 1
print(ans)

Solution (Python):
N = int(input())
enum = []

def dfs(n):
    if int(n) > N:  return
    if "3" in n and "5" in n and "7" in n:  enum.append(n)
    dfs(n + "3")
    dfs(n + "5")
    dfs(n + "7")
    
dfs("3")
dfs("5")
dfs("7")
print(len(enum))

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

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

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

    return result


def main():
    n = int(input())
    print(dfs('0', n))


if __name__ == '__main__':
    main()

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

nums = []
for i in range(9):
    if i == 0:
        nums_tmp = ['7', '5', '3']
    else:
        nums_tmp_tmp = []
        for num in nums_tmp:
            nums_tmp_tmp.extend([num + d for d in ('7', '5', '3')])
        nums_tmp = nums_tmp_tmp
    nums.extend(nums_tmp)

ans = 0
for num in nums:
    if ('7' in num) and ('5' in num) and ('3' in num) and (int(num) <= n):
        ans += 1
print(ans)

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

def dfs(u, n,c):
	if u > n:
		return
	if u != 0: 
		if set(str(u)) == set(['3','5','7']):
			c[0] += 1
	
	for digit in [3,5,7]: dfs(u*10 + digit,n,c)

c = [0]
dfs(0, n, c)
print c[0]

Solution (Python):
n = input()

d = {3: 0b001, 5: 0b010, 7: 0b100}

dp = [[[0] * 2 for _ in range(1 << 3)] for _ in range(len(n) + 1)]
dp[0][0][1] = 1

for i, e in enumerate(n):
    e = int(e)
    for num in [0, 3, 5, 7]:
        if num == 0:
            dp[i+1][0b000][0] += sum(dp[i][0b000])
            continue
        for j in range(1 << 3):
            if num == e:
                dp[i+1][j|d[num]][1] += dp[i][j][1]

            elif num < e:
                dp[i+1][j|d[num]][0] += dp[i][j][1]

            dp[i+1][j|d[num]][0] += dp[i][j][0]

ans = sum(dp[len(n)][0b111])
print(ans)

Solution (Python):
from itertools import product

n = int(input())

ans = 0
for i in range(1, 10):
    for pat in product("357", repeat=i):
        num = "".join(pat)
        st = set(num)
        if int(num) <= n and st == {"3", "5", "7"}:
            ans += 1

print(ans)

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter



import bisect
n=int(input())
l=[3,5,7]
res=set()
for i in range(3,10):
    for k in itertools.product(l,repeat=i):
        if 5 not in k or 3 not in k or 7 not in k:
            continue
        else:
            num=0
            for j in range(i):
                num+=k[j]*10**(i-j-1)
            res.add(num)
res=list(res)
res.sort()
ans=bisect.bisect_right(res,n)
print(ans)

Solution (Python):
n=int(input())
k=len(str(n))

from itertools import product

ans=0


for j in range(3,k+1):
    p=list(product([3,5,7],repeat=j)) 

    for c in p:
        if (3 not in c) or (5 not in c) or (7 not in c):
            continue
        
        tmp=''
        for i in c:
            tmp+=str(i)

        if int(tmp)<=n:
            ans+=1

print(ans)

Solution (Python):




n = int(input())

def dfs(val):
    
    if val > n:
        return

    A.append(val)

    for v in [3, 5, 7]:
        val = A.pop()
        dfs(10 * val + v)
        A.append(val)

A = []
for v in [3, 5, 7]:
    dfs(v)

res = 0
for v in A:
    s = str(v)
    if '3' in s and '5' in s and '7' in s:
        res += 1

print(res)

Solution (Python):
import sys
from itertools import product

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def solve753(K):
    tmp = []
    for v in product('357', repeat=K):
        if len(set(v)) == 3:
            tmp.append(int(''.join(v)))
    return tmp


def main():
    N = ii()
    d = len(str(N))
    cnt = 0
    for i in range(1, d+1):
        for v in solve753(i):
            if v <= N:
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):

dic = {7:4,5:2,3:1}
def getdic(n):
    return dic.get(n,0)
N = list(map(int,list(input())))

dp = [[[0]*8 for j in range(0,2,1)]for i in range(0,len(N),1)]

if N[0] in {3,5,7}:
    dp[0][0][getdic(N[0])] = 1
for i in (set(range(0,N[0]))&{3,5,7}):
    dp[0][1][getdic(i)] = 1

for i in range(1,len(N),1):
    dp[i-1][1][0]=1
    
    for k in range(0,8,1):
        dp[i][1][1|k] += dp[i-1][1][k]
        dp[i][1][2|k] += dp[i-1][1][k]
        dp[i][1][4|k] += dp[i-1][1][k]
    
    for k in range(1,8,1):
        for n in (set(range(0,N[i]))&{3,5,7}):
            dp[i][1][getdic(n)|k] += dp[i-1][0][k]
    
    if N[i] in {7,5,3}:
        for k in range(0,8,1):
            dp[i][0][getdic(N[i])|k] += dp[i-1][0][k]

print(dp[len(N)-1][0][7]+dp[len(N)-1][1][7])

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())

lim_keta=len(str(n))

def dfs(keta,num):
  if int(num)<=n and len(set(num))==3:
    global cnt
    cnt+=1

  if keta==lim_keta:
    return

  for i in '753':
    dfs(keta+1,num+i)

cnt=0
for i in '753':
  dfs(1,i)

print(cnt)

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

lim_keta=len(str(n))

def dfs(keta,num):
  global cnt
  if keta==lim_keta:
    if int(num)<=n and len(set(num))==3:
      cnt+=1
    return
  if len(set(num))==3:
    cnt+=1
  for i in '753':
    dfs(keta+1,num+i)

cnt=0
for i in '753':
  dfs(1,i)

print(cnt)

Solution (Python):
N = input()

L=len(N)

from itertools import product

check_num=[3,5,7]
check=[]

for l in range(1,L+1):
    for p in product(range(3),repeat=l):
        c=''
        for p_ in p:
            c+=str(check_num[p_])
        if len(set(c))==3 and int(c)<=int(N):
            check.append(int(c))
print(len(check))

Solution (Python):
N=int(input())
answer=[3,5,7]
for i in range(8):
  A=[i*10+3 for i in answer]
  C=[i*10+5 for i in answer]
  B=[i*10+7 for i in answer]
  answer.extend(A)
  answer.extend(B)
  answer.extend(C)
s=0
answer=list(set(answer))
for i in answer:
  if i<=N:
    if set(str(i))=={"3","5","7"}:
      s+=1
print(s)

Solution (Python):
from collections import deque, Counter

N = input()
l = len(N)

h = deque(['3','5','7'])
rlt = 0

while h:
  a = h.popleft()
  if int(N) >= int(a):
    dic = Counter(a)
    if dic['3'] > 0 and dic['5'] > 0 and dic['7'] > 0:
      rlt += 1
  if len(a) < l:
    for s in ('3','5','7'):
      h.append(a+s)
      
print(rlt)

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

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

Solution (Python):
n=int(input())
num=["3","5","7"]
l=["0"]
i=0
while True:
    for j in num:
        l.append(l[i]+j)
    i+=1
    if len(l[-1])==11:
        break

L=[]
for j in range(len(l)):
    if "3" in l[j] and "5" in l[j] and "7" in l[j] and int(l[j])<10**9:
        L.append(int(l[j]))
L.sort()

ans=0
for k in range(len(L)):
    if L[k]<=n:
        ans+=1
    else:
        break
print(ans)

Solution (Python):
N = input()
l = len(N)


def func(i, flag, b, only_leading_zero):
    if i == l:
        if b == 7:
            return 1
        else:
            return 0

    sum_ = 0
    flag_temp = flag
    for n in (0, 3, 5, 7):
        if not only_leading_zero and n == 0:
            continue

        if not flag and n > int(N[i]):
            continue

        if not flag and n < int(N[i]):
            flag = True

        if n == 3:
            x = 0b001
            only_leading_zero = False
        elif n == 5:
            x = 0b010
            only_leading_zero = False
        elif n == 7:
            x = 0b100
            only_leading_zero = False
        else:
            x = 0b000

        sum_ += func(i + 1, flag, b | x, only_leading_zero)
        flag = flag_temp

    return sum_


r = func(0, False, 0, True)
print(r)

Solution (Python):
N = input()
l = len(N)

dp = [[[[0] * 2 for _ in range(8)]for _ in range(2)] for _ in range(l + 1)]
dp[0][False][0][False] = 1

for i in range(l):
    cur = int(N[i])

    for j in (3, 5, 7):
        if j == 3:
            s = 0
        elif j == 5:
            s = 1
        elif j == 7:
            s = 2

        for k in range(8):
            new = k | (1 << s)
            dp[i + 1][True][new][True] += dp[i][True][k][True]
            dp[i + 1][True][new][True] += dp[i][True][k][False]

        if j < cur:
            for k in range(8):
                new = k | (1 << s)
                dp[i + 1][True][new][True] += dp[i][False][k][True]
                dp[i + 1][True][new][True] += dp[i][False][k][False]

        if j == cur:
            for k in range(8):
                new = k | (1 << s)
                dp[i + 1][False][new][True] += dp[i][False][k][True]
                dp[i + 1][False][new][True] += dp[i][False][k][False]

    dp[i + 1][True][0][False] += dp[i][False][0][False]
    dp[i + 1][True][0][False] += dp[i][True][0][False]


print(dp[l][True][7][True] + dp[l][False][7][True])

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


def f(s):

    if int(s) > N:
        return 0

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


print(f('0'))

Solution (Python):
import itertools
import bisect

lis = list(itertools.product('7530',repeat = 9))
int_lis = list(map(int,map(''.join,lis)))
str_lis = list(map(str,int_lis[:-16]))
lis = []
for s in str_lis:
    if ('7' in s) and ('5' in s) and ('3' in s) and ('0' not in s) :
        lis.append(int(s))
print(bisect.bisect_right(sorted(lis),int(input())))

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

count = 0


def calc(n, n3, n5, n7):
    global count
    if n > N:
        return
    if 1 <= n <= N and n3 and n5 and n7:
        count += 1
    calc(10 * n + 3, 1, n5, n7)
    calc(10 * n + 5, n3, 1, n7)
    calc(10 * n + 7, n3, n5, 1)


calc(0, 0, 0, 0)
print(count)

Solution (Python):
import itertools
n=int(input())
cnt=0
for j in range(1, len(str(n))+1):
  lst=(list(itertools.product([3, 5, 7], repeat=j)))
  for i in range(len(lst)):
    temp=int("".join(map(str, lst[i])))
    if "3" in str(temp) and "5" in str(temp) and "7" in str(temp) and temp<=n:
      cnt+=1
print(cnt)

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

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

    return ret 
    
print(dfs('0'))

Solution (Python):
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

N = int(input())

ans = 0
for n in range(3, 10):
    for l in it.product(["7", "5", "3"], repeat=n):
        if "7" not in l or "5" not in l or "3" not in l:
            continue
        M = int("".join(l))
        if M <= N:
            dump(M, ans)
            ans += 1
dump(N)
print(ans)

Solution (Python):
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

N = int(input())

ans = 0
for n in range(3, 10):
    for l in it.product(["7", "5", "3"], repeat=n):
        if "7" not in l or "5" not in l or "3" not in l:
            continue
        M = int("".join(l))
        if M <= N:
            dump(M, ans)
            ans += 1
dump(N)
print(ans)

Solution (Python):
def make753(n):
    ns = str(n)
    l = len(ns)* -1
    flg = True
    while flg:
        for i in range(-1, l-1, -1):
            if ns[i] == '3' or ns[i] == '5':
                ii = (i+1)*-1
                n += 10**ii*2
                flg = False
                break
            if ns[i] == '7':
                ii = (i+1)*-1
                n -= 10**ii*4
                flg = False
                continue
    ns = str(n)
    for j in range(len(ns)):
        if not ns[j] == '3':
            break
        if j == len(ns) - 1:
            n = 10*n+3
    return n


def check753(n):
    ns = str(n)
    l = len(ns)
    a = []
    for i in range(l):
        a.append(int(ns[i]))
    a = list(set(a))
    if len(a) == 3:
        return True
    else:
        return False

n = int(input())
a = 333
cnt = 0

while a <= n:
    if check753(a):
        cnt += 1
    a = make753(a)
print(cnt)

Solution (Python):
N = int(input())
from collections import deque
def main():
    ans = 0
    targets = deque()
    targets.append('3')
    targets.append('5')
    targets.append('7')
    while targets:
        s = targets.popleft()
        if int(s) <= N:
            if '3' in s and '5' in s and '7' in s:
                ans += 1
            targets.append(s+'3')
            targets.append(s+'5')
            targets.append(s+'7')

    print(ans)
main()

Solution (Python):
from itertools import product
n = int(input())
i = len(str(n))

cnt = 0
for j in range(3, i+1):
    for k in product(["3", "5", "7"], repeat=j):
        if len(set(k)) != 3:
            continue
        if int("".join(k)) <= n:
            cnt += 1

print(cnt)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
q = deque([3,5,7])
res = 0
def chk(s):
    global res
    if min(s.count('3'), s.count('5'), s.count('7')) > 0:
        res += 1
while q:
    now = q.popleft()
    if now > n:
        continue
    chk(str(now))
    for t in ['3', '5', '7']:
        q.append(int(str(now) + t))
print(res)