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):
n = int(input())
def sgs(digit):
  ans = []
  if digit == 1:
    return ["7", "5", "3"]
  else:
    sgs_pre = sgs(digit - 1)
    for str in sgs_pre:
      ans.append(str + "7")
      ans.append(str + "5")
      ans.append(str + "3")
    else:
      return ans
digit = len(str(n))
counter = 0
for i in range(3, digit+1):
  for num in sgs(i):
    if "7" in num and "5" in num and "3" in num:
      if int(num) <= n:
        counter += 1
print(counter)

Solution (Python):

n = int(input())

su753 = set([0])


for _ in range(10):
    tmp = set()
    for x in su753:
        tmp |= set(x*10+y for y in [3,5,7])
    su753 |= tmp 

st = set(str(x) for x in su753 if x<=n)
st = set(x for x in st if set(x)==set('357'))
print(len(st))

Solution (Python):


n = int(input())

def f(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 += f(s+c)
    return ret
        
print(f('0'))

Solution (Python):
def dfs(n,num):
	if int(num) > n:
		return 0
	ret = ("3" in num and "5" in num and "7" in num)
	for i in "357":
		ret += dfs(n,num + i)
	return ret

n = int(input())
print(dfs(n,"0"))

Solution (Python):


def make_753number(n):
    s = str(n)
    if '7' in s and '5' in s and '3' in s:
        n753.add(n)
    if n <= 10**9:
        make_753number(10 * n + 7)
        make_753number(10 * n + 5)
        make_753number(10 * n + 3)


n753 = set()
make_753number(0)
N = int(input())
print(len([1 for n in n753 if n <= N]))

Solution (Python):

N = int(input())

ans = 0
stack = ['7', '5', '3']
while len(stack) != 0:
    nums = stack.pop()
    if int(nums) > N:
        pass

    else:
        if all([nums.count(c) > 0 for c in '753']):
            ans += 1

        for c in '753':
            stack.append(nums + c)



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, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()

ret = 0
for l in range(1, len(str(n)) + 1):
    for i in product(*[('3', '5', '7') for _ in range(l)]):
        num = ''.join(i)
        if '3' not in num or '5' not in num or '7' not in num or int(num) > n:
            continue
        ret += 1


print(ret)

Solution (Python):
n=int(input())
def count(num):
    total=0
    if int(num)>n:
        return 0
    if ("3" in num and "5" in num and "7" in num):
        total+=1
        
    for i in "357":
        total+=count(num+i)
    return total
print(count("0"))

Solution (Python):
import math
N = int(input())
if N < 357:
    print(0)
else:
    k = 1
    ans = 0
    while(10**k < N):
        k += 1
    
    nums=set()
    for i in range(1,4**k):
      num=0
      flag=[False,False,False,False]
      for j in range(k):
        tmp= (i // (4**j))%4
       
        if flag[3] and tmp<3:
          flag[tmp-1]=False
            
          break
        else:
          flag[tmp-1]=True
          
        if tmp==1:
          num+=3*(10**j)
        elif tmp==2:
          num+=5*(10**j)
        elif tmp==3:
          num+=7*(10**j)
        else:
          if j<3:
            break    
      
      
      for i in range(3):
        if flag[i]:
          if i == 2 and num<=N:
            nums.add(num)
        else:
          break
    forbidden=set()
    for x in nums:
      x=str(x)
      if "0" in x:
        forbidden.add(x)
    print(len(nums)-len(forbidden))

Solution (Python):
import itertools
import bisect

tfs = ['3', '5', '7']
lst = list()
for i in range(3, 10):
    lst += itertools.product(tfs, repeat=i)
lst = sorted([int(''.join(z)) for z in filter(lambda x: all([(y in x) for y in tfs]), lst)])
n = int(input())
print(bisect.bisect(lst, n))

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

Solution (Python):

N = int(input())



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

print(dfs("0"))

Solution (Python):

N = int(input())

from functools import lru_cache
@lru_cache(maxsize=1000)
def dfs(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 += dfs(s+c) 
    return ret

print(dfs("0"))

Solution (Python):
from functools import reduce
n = int(input())

ans = 0
def dfs(numl):
    global ans
    if 3 in numl and 5 in numl and 7 in numl and n >= reduce( lambda a,b:10*a+b, numl):
        ans += 1
    if len(str(n)) > len(numl):
        for i in [3,5,7]:
            dfs(numl+[i])

dfs([])
print(ans)

Solution (Python):
def next_rank_num(nStr):
  if nStr == '3':
    return '5'
  elif nStr == '5':
    return '7'
  elif nStr == '7':
    return '3'

def next_num(nStr):
  length = len(nStr)
  i = 1
  nrn = '3'
  nList = []
  while i <= length and nrn == '3':
    nrn = next_rank_num(nStr[length-i])
    nList.append(nrn)
    if nrn == '3':
      i += 1
  nList.reverse()
  if i > length:
    return '3' + ''.join(nList)
  else:
    return nStr[0:length-i] + ''.join(nList)
   
num = int(input())
count = 0
nStr = "357";
while int(nStr) <= num:
  if len({'3', '5', '7'} - set(nStr)) == 0:
    count += 1
  nStr = next_num(nStr)
print(str(count))

Solution (Python):
import sys
sys.setrecursionlimit(2000)

n = int(input())

def dfs(is3, is5, is7, s):
    if s != "" and int(s) > n:
        return 0
    else:
        ans = 0
        if is3 and is5 and is7:
            ans += 1
        ans += dfs(True, is5, is7, s + "3")
        ans += dfs(is3, True, is7, s + "5")
        ans += dfs(is3, is5, True, s + "7")
    return ans

print(dfs(False,False,False,""))

Solution (Python):
import itertools

N = input()

element= [3,5,7]

nums = []

for i in range(3,len(N) + 1):
  num = itertools.product(element, repeat = i)
  for j in num:
    if len(set(j)) == 3:
      nums.append(j)

con = 0

numlist = []

for i in range(0,len(nums)):
  S = ""
  for j in range(0,len(nums[i])):
    S += str(nums[i][j])
  S = int(S)
  numlist.append(S)
  
print(len([i for i in numlist if i <= int(N)]))

Solution (Python):
n=int(input())
cnt=0 
dp=[[[0 for j in range(10)]for i in range(10)]for k in range(10)]
ans=[0]
arr=[0]
vis=set()
vis.add(0)
while arr: 
    t=arr.pop(0)
    a=t*10+3 
    b=t*10+5 
    c=t*10+7 
    def ok(x):
        return x<=n and x not in vis 
    for i in [a,b,c]:
        if ok(i):
            vis.add(i)
            ans.append(i)
            arr.append(i)
ans.sort()
from bisect import bisect_left as bl 
c=0 
def valid(a):
    one=0 
    two=0 
    three=0 
    while a: 
        if a%10==3:
            one+=1 
        if a%10==5:
            two+=1 
        if a%10==7:
            three+=1 
        a//=10 
    if one==0 or two==0 or three==0:
        return 0 
    return 1 
for i in ans: 
    if valid(i):
        c+=1 
    if i>n:
        break 
print(c)

Solution (Python):

import sys




import itertools





shichigosan = '357'

def main():

    n = int(sys.stdin.readline().rstrip())
    
    count = 0
    for i in range(3, len(str(n)) + 1):
        sub_shichigosan = list(''.join(s) for s in itertools.product(shichigosan, repeat=i))
        for sub in sub_shichigosan:
            for d in shichigosan:
                if d in sub:
                    continue
                else:
                    break
            else:
                if 357 <= int(sub) <= n:
                    count += 1
    
    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    N_len = len(str(N))
    if N_len < 3:
        return print(0)
    from itertools import product
    ans_set = set()
    for k in range(3, N_len+1):
        ans_set = ans_set.union({s for s in product("753", repeat=k)
                                 if int("".join(s)) <= N and
                                 len(set(s) & set("753")) == 3})
    print(len(ans_set))


if __name__ == '__main__':
    main()

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

    def recur(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 += recur(s + c)
        return ret
    print(recur('0'))


if __name__ == '__main__':
    main()

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

    def recur(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 += recur(s + c)
        return ret
    print(recur('0'))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    N_len = len(str(N))
    if N_len < 3:
        return print(0)
    from itertools import product
    ans_set = set()
    for k in range(3, N_len+1):
        ans_set = ans_set.union({s for s in product("753", repeat=k)
                                 if int("".join(s)) <= N and
                                 len(set(s) & set("753")) == 3})
    print(len(ans_set))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    N_len = len(str(N))
    if N_len < 3:
        return print(0)
    from itertools import product
    ans_set = set()
    for k in range(3, min(N_len, 9)+1):
        ans_set = ans_set.union({s for s in product("753", repeat=k)
                                 if int("".join(s)) <= N and
                                 len(set(s) & set("753")) == 3})
    print(len(ans_set))


if __name__ == '__main__':
    main()

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

n = int(stdin.readline().rstrip())

li = [7,5,3]

if n < 357:
    print(0)
    exit()

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

kazu = 0
point = 0
k = "0"
while int(k) <= n:
    k = Base_10_to_n(kazu,4)
    if k.count("0") > 0:
        kazu += 1
        continue
    k = k.replace("3","7").replace("1","3").replace("2","5")
    if all(k.count(c)>0 for c in "753"):
        if int(k) <= n:
            point += 1
    kazu += 1
print(point)

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

n = int(stdin.readline().rstrip())

li = [7,5,3]

if n < 357:
    print(0)
    exit()

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

kazu = 0
point = 0
k = "0"
while int(k) <= n:
    k = Base_10_to_n(kazu,4)
    k = k.replace("3","7").replace("1","3").replace("2","5")
    if all(k.count(c)>0 for c in "753")and k.count("0") == 0:
        if int(k) <= n:
            point += 1
    kazu += 1
print(point)

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

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

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
def n(s):
    if int(s) > N:
        return 0
    if '7' in s and '5' in s and '3' in s:
        p = 1
    else:
        p = 0
    p += n(s+'7')
    p += n(s+'5')
    p += n(s+'3')
    return p
print(n('0'))

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


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

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

    print(dfs('0'))


if __name__ == '__main__':
    main()

Solution (Python):
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

n = int(input())
c = 0
for i in range(4**9):
  cur = Base_10_to_n(i, 4)
  if '0' in cur:
    continue
  if cur.count('1') == 0 or cur.count('2') == 0 or cur.count('3') == 0:
    continue
  cur = cur.translate(str.maketrans('123', '357'))
  if int(cur) <= n:
    c += 1
print(c)

Solution (Python):
from itertools import product

n = input()
m = []
for i in range(3, len(n)+1):
    m += [int(''.join(j)) for j in product(['3','5','7'], repeat=i) if len(set(j)) == 3]

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

print(ans)

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

def dfs(x):
    if int(x)>n:
        return 0
    else:
        check=True
        for i in "753":
            if x.count(i)==0:
                check=False
        if check:
            ans=1
        else:
            ans=0
    
    for i in "753":
        ans+=dfs(x+i)
    
    return ans

print(dfs("0"))

Solution (Python):
Table=[0,0,0,6,42,192,732,2538,8334,26484]
N=int(input())
K=len(str(N))
ans=Table[K-1]

import itertools
U=['3','5','7']
PRD = list(itertools.product(U, repeat=K))
for i in PRD:
    T=''.join(i)
    if int(T)>N:
        break
    if '3' in T and '5' in T and '7' in T:
        ans+=1

print(ans)

Solution (Python):
import numpy as np
import itertools

N = int(input())
count = 0

X = [[3,5,7]]*9
X = np.array(X)

result = [[] for i in range(9)]


for n in range(9):
    X[n] = X[n] * (10 ** n)

result[0] = [3,5,7]

for n in range(1,9):
    for x in X[n]:
        for r in result[n-1]:
            result[n].append(x+r)

result = list(itertools.chain.from_iterable(result))

for r in result:
    if r < 333:
        pass
    elif r > N:
        pass
    else:
        if ('3' in str(r)) and ('5' in str(r)) and ('7' in str(r)):
            count += 1

print(int(count))

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = 0
def f(x):
    global res
    if x <= n:
        l = len(str(x))
        f(3*10**l+x)
        f(5*10**l+x)
        f(7*10**l+x)
        if '3' in str(x) and '5' in str(x) and '7' in str(x):
            res += 1
f(3)
f(5)
f(7)
print(res)

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

def sft(s):
	global cnt
	if int(s) > n:
		return
	if "3" in s and "5" in s and "7" in s:
		cnt += 1
	sft(s+"3")
	sft(s+"5")
	sft(s+"7")

sft("0")
print(cnt)

Solution (Python):
N = int(input())
def dfs(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 += dfs(S+c)
    return ret
print(dfs('0'))

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

def func(s, cnt):
    if int(s)>N:
        return cnt
    else:
        b=list(s)
        if '7' in b and '5' in b and '3' in b:
            cnt += 1
        for t in "753":
            cnt = func(s+t, cnt)
        return cnt
    
print(func("0", 0))

Solution (Python):
Ns = input()
N = int(Ns)
Nl = len(Ns)
ret = 0
def doit(t, f , s, now):
    global ret
    if t + f + s == 0:
        if int(now) <= N:
            ret += 1
        return
    if t > 0:
        doit(t - 1, f, s, now + str(3)) 
    if f > 0:
        doit(t, f - 1, s, now + str(5)) 
    if s > 0:
        doit(t, f, s - 1, now + str(7)) 
    
for seven in range(1, Nl - 1):
    for five in range(1, Nl - seven):
        least = Nl - seven - five
        for three in range(1, least + 1):
            doit(three, five, seven, '')

print(ret)

Solution (Python):
Ns = input()
N = int(Ns)
Nl = len(Ns)
ret = []
def doit(t, f , s, now):
    if t + f + s == 0:
        if int(now) <= N:
            ret.append(now)
        return
    if t > 0:
        doit(t - 1, f, s, now + str(3)) 
    if f > 0:
        doit(t, f - 1, s, now + str(5)) 
    if s > 0:
        doit(t, f, s - 1, now + str(7)) 
    
for seven in range(1, Nl - 1):
    for five in range(1, Nl - seven):
        least = Nl - seven - five
        for three in range(1, least + 1):
            doit(three, five, seven, '')

print(len(ret))

Solution (Python):
n = int(input())
l = 1
s = {0}
r = []
for i in range(0, 10):
  t = set()
  for a in s:
    for b in [3, 5, 7]:
      t.add(a + (10 ** i) * b)
  r += t
  s = t

count = 0
for a in r:
  s = str(a)
  if (357 <= a <= n) and '3' in s and '5' in s and '7' in s:
    count += 1
print(count)

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):
S = input()

seed = [3,5,7]
nums = [3,5,7]
next = []

for i in range(8):
    next = nums[:]
    for n in nums:
        for s in seed:
            next.append(n*10+s)
    nums = next[:]
    next = []

cnt = 0
nums = list(set(nums))
for n in nums:
    s = str(n)
    if '3' in s and '7' in s and '5' in s and n <= int(S):
        cnt += 1

print(cnt)

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

import itertools

li=[]

for i in range(3,11):
  for j in itertools.product("357", repeat=i):
    if "3" in j and "5" in j and "7" in j:
      li.append(int("".join(j)))
i=0
while li[i]<=n:
  i+=1
print(i)

Solution (Python):
import os, sys, re, math

N = input()

def get_count(s, count):
    z = s.find('*')
    t = s
    for c in '7530':
        if c == '0' and len(t[:z].replace('0', '')) > 0:
            continue
        t = t[:z] + c + t[z + 1:]
        if z < len(s) - 1:
            count = get_count(t, count)
        else:
            if int(t) <= int(N) and t.find('7') >= 0 and t.find('5') >= 0 and t.find('3') >= 0 and t.find('0') <= 0:
                count += 1
    return count

count = get_count('*' * len(N), 0)
print (count)

Solution (Python):
def yonsin(X):
    if(int(X/4)):
        return yonsin(int(X/4))+str(X%4)
    return str(X%4)

n = int(input())
i = 0
yon = 0
cnt = 0
while (True):
	i += 1
	yon = yonsin(i)      
	if ('1' in yon and '2' in yon and '3' in yon and '0' not in yon):
		henkan = yon.replace('3','7').replace('2','5').replace('1','3')
		if (int(henkan) > n):
			break
		cnt += 1
print (cnt)

Solution (Python):
Ns = input()
N = int(Ns)
Nl = len(Ns)
ret = set()
def doit(t, f , s, now):
    if t + f + s == 0:
        if int(now) <= N:
            ret.add(now)
        return
    if t > 0:
        doit(t - 1, f, s, now + str(3)) 
    if f > 0:
        doit(t, f - 1, s, now + str(5)) 
    if s > 0:
        doit(t, f, s - 1, now + str(7)) 
    
for seven in range(1, Nl - 1):
    for five in range(1, Nl - seven):
        least = Nl - seven - five
        for three in range(1, least + 1):
            doit(three, five, seven, '')

print(len(ret))

Solution (Python):
limit = int(input())
seed = [3,5,7]
set357 = set(seed)
def valid(n):
    x_set = set()
    while(n > 0):
        x_set.add(n % 10)
        n //= 10
    return int(x_set == set357)
def f(current):
    ans = valid(current)
    for s in seed:
        temp = (current * 10) + s
        if temp <= limit:
            ans += f(temp)
    return ans

print(f(0))

Solution (Python):
n = int(input())
def doit(s):
    if len(s) > 0 and int(s) > n:
        return 0
    ret = 1 if '3' in s and '5' in s and '7' in s else 0
    for d in '357':
        ret += doit(d + s)
    return ret
print(doit(''))

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

def doit(num):
    if num and int(num) > n:
        return 0
    count = all(d in num for d in '735')
    for d in '735':
        count += doit(num + d)
    return count

print(doit(''))

Solution (Python):
num=int(input())
def dfs(n):
  if n>num:
    return 0
  else:
    w=str(n)
    if w=="0":
      w=""
    if "3" in w and "7" in w and "5" in w:
      ret=1
    else:
      ret=0
    for i in "357":   
      ret+=dfs(int(i+w))
    return ret
print(dfs(0))

Solution (Python):
from collections import deque
n=int(input())
l=["3","5","7"]
q=deque(["3","5","7"])
l1=["3","5","7"]
count=0
while q:
  a=q.popleft()
  for i in l:
    if int(i+a)<=n:
      q.append(i+a)
      l1.append(i+a)
for i in l1:
  if ("3" in i) and ("5" in i) and ("7" in i):
    count+=1
print(count)

Solution (Python):
import itertools

N = input()

A = []
nums = [3,5,7]
con = 0

for i in range(3,len(N) + 1):
  A += list(itertools.product(nums,repeat = i))

L = []

for i in range(0,len(A)):
  a = set(list(A[i]))
  if len(a) == 3:
    L.append(A[i])

Slist = []
    
for i in range(0,len(L)):
  S = ""
  for j in range(0,len(L[i])):
    S += str(L[i][j])
  S = int(S)
  Slist.append(S)

print(len([c for c in Slist if c <= int(N)]))

Solution (Python):
n = int(input())
nums = "357"

def dfs(s):
    if int(s) > n: return 0
    res = int(all(num in s for num in nums))
    for num in nums:
        res += dfs(s + num)
    return res

print(dfs("0"))

Solution (Python):
from collections import deque
n=int(input())
ans=0
start=["0"]
start=deque(start)
while start:
  s=start.popleft()
  if int(s)<=n and "3" in s and "5" in s and "7" in s:ans+=1
  elif int(s)>n:continue
  for i in ["3","5","7"]:
    start.append(s+i)
print(ans)

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

print(dfs('0'))

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

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

print(dfs('0'))

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

print(dfs('0'))

Solution (Python):
def appendedList(arr, val):
    ret = arr.copy()
    ret.append(val)
    return ret

def dfs(cur, target, ret):
    if 0 < len(cur):
        if target < int(''.join(map(str, cur))):
            return 0
    const = 1 if (3 in cur and 5 in cur and 7 in cur) else 0
    ret3 = dfs(appendedList(cur, 3), target, ret)
    ret5 = dfs(appendedList(cur, 5), target, ret)
    ret7 = dfs(appendedList(cur, 7), target, ret)
    return ret + const + ret3 + ret5 + ret7

if __name__ == '__main__':
    N = int(input())
    print(dfs([], N, 0))

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

print(dfs('0'))

Solution (Python):
def to753(k,d):
    res=0
    for j in range(d):
        res+=(3+2*(k%3))*10**j
        k//=3
    return res

def has753(x):
    f3=f5=f7=False
    while x>0:
        f3=f3 or x%10==3
        f5=f5 or x%10==5
        f7=f7 or x%10==7
        x//=10
    return f3 and f5 and f7

N=int(input())

ans=0

fEND=False

for d in range(3,10):
    if fEND:break
    for k in range(3**d):
        x=to753(k,d)
        if x>N:fEND=True;break
        if has753(x):
            ans+=1

print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)


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

    res = 0
    if all(c in s for c in '753'):
        res += 1

    for c in '753':
        res += dfs(s + c)

    return res


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

Solution (Python):
n=input()
l=len(n)
n=int(n)
data=[["0"]*l for i in range(4**l)]
for i in range(4**l):
    k=i
    for j in range(l):
        a=k//4**(l-1-j)
        if a==1:
            data[i][j]="3"
        if a==2:
            data[i][j]="5"
        if a==3:
            data[i][j]="7"
        k%=4**(l-1-j)
ans=0
for u in data:
    num=int("".join(u))
    if num<=n:
        num=str(num)
        if "0" not in num and "3" in num and "5" in num and "7" in num:
            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
n = int(input())
if n < 357:
  print(0)
  sys.exit()

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):
s=input()
u=int(s)
n=len(s)

if n<=2:
  print(0)
  exit()

f=[0 for _ in range(3)]
a=0

for k in range(1,n+1):
  for i in range(3**k):
    d=i
    t=0
    f[0]=f[1]=f[2]=0
    for j in range(k):
      f[d%3]=1
      t+=(2*(d%3)+3)*10**j
      d = d//3
    if f[0]*f[1]*f[2]:
      if t <= u:
        a+=1

print(a)

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):
    ans=0
    if int(s)>n:
        return 0
    else:
        ans+=all(map(s.count,"357"))
        for i in "357":
            ans+=dfs(s+i)
    return ans
print(dfs("0"))

Solution (Python):
import copy

n = input()
a = {'7','5','3'}
for _ in range(len(n)-1):
    b = copy.copy(a)
    for s in a:
        for i in [7,5,3]:
            b.add(s + str(i))
    a = b
a = {i for i in a if not ('3' not in i or '5' not in i or '7' not in i)}

n = int(n)
a = {i for i in a if int(i)<=n}
print(len(a))

Solution (Python):
import copy

n = input()
a = {'7','5','3'}
for _ in range(len(n)-1):
    b = copy.copy(a)
    for s in a:
        for i in (7,5,3):
            b.add(s + str(i))
    a = b
a = {i for i in a if not ('3' not in i or '5' not in i or '7' not in i)}

n = int(n)
a = {i for i in a if int(i)<=n}
print(len(a))

Solution (Python):
import copy

n = input()
a = {'7','5','3'}
for _ in range(len(n)-1):
    b = copy.copy(a)
    for s in a:
        for i in (7,5,3):
            b.add(s + str(i))
    a = b
a = {i for i in a if not ('3' not in i or '5' not in i or '7' not in i)}

n = int(n)
a = {i for i in a if int(i)<=n}
print(len(a))

Solution (Python):


n=int(input())
lists=[3,5,7]
def caliculate(n):
    if n==1:
        return lists
    elif n>=2:
        listsed=[0]*(3**n)

        index=0
        x=caliculate(n-1)

        for i in x:
            listsed[index]=10*i+3
            index+=1
            listsed[index]=10*i+5
            index+=1
            listsed[index]=10*i+7
            index+=1
        return listsed
ans=0
for i in range(1,10):
    for some in caliculate(i):
        if all( str(i) in str(some) for i in lists) and some<=n:
            ans+=1
print(ans)

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

Solution (Python):
import math, itertools

N = int(input())

n_digit = int(math.log10(N))+1




memo = [-1]*10
def shichigosan(digit):
    if memo[digit] != -1:
        output = memo[digit]
    else:
        output = set(itertools.product([3, 5, 7], repeat=digit))
        tmp = set(itertools.product([3,5], repeat=digit))|set(itertools.product([5,7], repeat=digit))|set(itertools.product([3,7], repeat=digit))
        output -= tmp
        memo[3] = output
        memo[digit] = output
    return output

ans = 0
for i in range(3,n_digit):
    ans += len(shichigosan(i))

ans += len([x for x in shichigosan(n_digit) if int("".join(map(str, x))) <= N])

print(ans)

Solution (Python):
def slove():
    import sys
    import itertools
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    ls = list("357")
    cnt = 0
    for i in range(1, 10):
        for v in itertools.product(ls, repeat=i):
            if "3" in v and "5" in v and "7" in v:
                t = int("".join(v))
                if t > n:
                    break
                else:
                    cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

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


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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

semi = []
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())

numlist=set(['3','5','7'])
for i in range(8):
    numlist2=set()
    for num in numlist:
        numlist2.add('3'+num)
        numlist2.add('5'+num)
        numlist2.add('7'+num)
    numlist = numlist.union(numlist2)
    

def chk753(a):
    c3=0
    c5=0
    c7=0
    for i in range(len(a) ):
        if a[i]=='7':
            c7+=1
        elif a[i] == '5':
            c5+=1
        elif a[i] == '3':
            c3+=1
    if c7>0 and c5>0 and c3>0 :
        return True
    else:
        return False

def chkN(a,N):
    if int(a) <= N:
        return True
    else:
        return False

cnt=0
for t in numlist:
    if chk753(t) and chkN(t,N):
        cnt+=1
        

print(cnt)