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 math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
num = ['7', '5', '3']
stack = [('', 0)]
ans = 0
check = defaultdict(lambda:True)
while stack:
    m, l = stack.pop()
    for x in num:
        if x not in m:
            break
    else:
        ans += 1
    for x in num:
        if 10 * l + int(x) <= n:
            if check[10*l + int(x)]:
                stack.append((m + x, 10 * l + int(x)))
                check[10*l + int(x)] = False
print(ans)

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

def dfs(s):
    if int(s) <= n:
        ans = 1 if all(s.count(x) > 0 for x in "357") else 0
        for x in "357":
            ans += dfs(s+x)
    else:
        return 0
    return ans

print(dfs("0"))

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

lst = ['3','5','7']
anslst = []
for i in range(1,10):
    for v in itertools.product(lst,repeat=i):
        x = Counter(str(v))
        if x['7'] >= 1 and x['5'] >= 1 and x['3'] >= 1:
            anslst.append(int(''.join(v)))
anslst.sort()
index = bisect.bisect_right(list(anslst), N)
print(index)

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


def dfs(a, ans):
    if a > n:
        return ans
    if set(list(str(a))) == rule:
        ans += 1
    for v in [3, 5, 7]:
        a = a * 10 + v
        ans = dfs(a, ans)
        a //= 10
    return ans


n = int(readline())

rule = set(('3', '5', '7'))
ans = 0

print(dfs(0, ans))

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque


from collections import Counter

import itertools

from heapq import heapify,heappop,heappush


from functools import lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]

def main():
    N=int(input())
    A=(0,3,5,7)
    ans=0
    for x in itertools.product(A, repeat=9):
        num=0
        for i,xi in enumerate(x):
            num+=10**i*xi
        sn=str(num)
        if num>N or "0" in sn:
            continue
        if "3" in sn and "5" in sn and "7" in sn:
            ans+=1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
A = []
str = "357"
lim = 11

def dfs(bef, sz):
    if sz + 1 == lim:
        return
    for i in str:
        t = bef + i
        A.append(t)
        dfs(t, sz + 1)

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

    dfs("", 0)

    ans = 0

    for a in A:
        q = False
        w = False
        e = False
        for i in a:
            if i == '3':
                q = True
            elif i == '5':
                w = True
            elif i == '7':
                e = True
        if q and w and e:      
            ai = int(a)
            if ai <= n:
                ans += 1

    print(ans)

main()

Solution (Python):
import itertools
n = int(input())
cnt = 0
for i in range(3,len(str(n))+1):
    for v in itertools.product(["3","5","7"], repeat=i):
        if len(set(v))!=3: continue
        x = int("".join(v))
        if n >= x: cnt += 1

print(cnt)

Solution (Python):
from collections import deque
def bfs(n):
    ans = 0
    queue = deque([3,5,7])

    while queue:
        num = queue.popleft()

        if num > n:
            return ans

        for i in [3,5,7]:
            queue.append(num*10+i)

        st = str(num)
        if '3' in st and '5' in st and '7' in st:
            ans += 1


n = int(input())
print(bfs(n))

Solution (Python):
def base10toN(num, base):
    converted_string, modstring = "", ""
    currentnum = num
    if not num:
        return '0'
    while currentnum:
        mod = currentnum % base
        currentnum = currentnum // base
        converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string
    return converted_string
n=int(input())
ans=0
for i in range(4**9):
  s=base10toN(i,4)
  a=[]
  for j in range(len(s)):
    a.append(s[j])
  a.reverse()
  for j in range(9-len(s)):
    a.append('0')
  a.reverse()
  count0=0
  count1=0
  count2=0
  for j in range(9):
    if a[j]=='1':
      count0+=1
    if a[j]=='2':
      count1+=1
    if a[j]=='3':
      count2+=1
  if count0==0 or count1==0 or count2==0:
    continue
  b=[]
  for j in range(9):
    if a[j]=='0':
      b.append('0')
    if a[j]=='1':
      b.append('3')
    if a[j]=='2':
      b.append('5')
    if a[j]=='3':
      b.append('7')
  flag=0
  fail=0
  for j in range(9):
    if a[j]!='0':
      flag=1
    if flag==1 and a[j]=='0':
      fail=1
      break
  if fail==1:
    continue
  p=int(''.join(b))
  if p<=n:
    ans+=1
  else:
    break
print(ans)

Solution (Python):
from itertools import product
from bisect import bisect_right
A = []
for i in range(3,10):
    for z in product(("3","5","7"),repeat=i):
        C = {"3":0,"5":0,"7":0}
        for j in range(i):
            C[z[j]] += 1
        if C["3"]>0 and C["5"]>0 and C["7"]>0:
            x = int("".join(z))
            A.append(x)
A = sorted(A)
N = int(input())
ind = bisect_right(A,N)
print(ind)

Solution (Python):
def resolve():
    from collections import deque

    def checker(n):
        n = str(n)
        OK3 = False
        OK5 = False
        OK7 = False
        for i in n:
            if i == "3":
                OK3 = True
            elif i== "5":
                OK5 = True
            elif i == "7":
                OK7 = True
        if OK3 and OK5 and OK7:
            return True
        else:
            return False

    n = int(input())
    if n < 357:
        print(0)
    else:
        ans = 0
        nxt = [3, 5, 7]
        nxt = deque(nxt)
        OK = True
        while OK:
            a = nxt.popleft()
            if a > n:
                break
            nxt.append(a*10+3)
            nxt.append(a * 10 + 5)
            nxt.append(a * 10 + 7)
            if checker(a):
                ans += 1
        print(ans)
resolve()

Solution (Python):
import itertools
N = int(input())
A = [3,5,7]
s = len(str(N))
ALL = []
for keta in range(3,s+1):
  ALL.extend(list(itertools.product(A, repeat=keta)))

ans = 0
for num in ALL:
  L = set(num)
  if 3 not in L or 5 not in L or 7 not in L:
    continue
  temp = ""
  for i in num:
    temp += str(i)
  number = int(temp)
  if number <= N:
    
    ans += 1
print(ans)

Solution (Python):
import sys









input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 1000000007

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

    tmp = 0
    if "3" in s and "5" in s and "7" in s:
        
        tmp += 1
    tmp += dfs(n, s + "3")
    tmp += dfs(n, s + "5")
    tmp += dfs(n, s + "7")
    return tmp


def solve():
    n = getN()
    ans = dfs(n, "")
    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    
    solve()

Solution (Python):
n = int(input())
s = [0]
l = []
while s:
    p = s.pop()
    if p > n:
        continue
    l.append(p)
    s.append(p * 10 + 3)
    s.append(p * 10 + 5)
    s.append(p * 10 + 7)
ans = 0
for x in l:
    p = str(x)
    if p.count('3') and p.count('5') and p.count('7'):
        ans += 1
print(ans)

Solution (Python):
N=int(input())
P=0
def f(x):
  global N,P
  if x>N:
    return None
  s=str(x)
  if '7' in s and '5' in s and '3' in s:
    P+=1
  f(x*10+7)
  f(x*10+5)
  f(x*10+3)
f(7)
f(5)
f(3)
print(P)

Solution (Python):
def solve():
    n = int(input())
    print(dfs('0', n))


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


if __name__ == '__main__':
    solve()

Solution (Python):
from itertools import product

N = int(input())

_357 = {'3', '5', '7'}

ans = 0
for r in range(3, len(str(N)) + 1):
    for numbers in product(('3', '5', '7'), repeat=r):
        if set(numbers) == _357 and int(''.join(numbers)) <= N:
            ans += 1

print(ans)

Solution (Python):
from itertools import product
 
n = int(input())
 
tfs = set()
for i in range(3,10):
    tfs |= set(product(['3', '5', '7'], repeat=i))

cnt = 0
for l in tfs:
    if ('3' in l) and ('5' in l) and ('7' in l):
        num = int(''.join(l))
        if num <= n:
            cnt += 1
print(cnt)

Solution (Python):
from itertools import product

n = int(input())

tfs = set()
for i in range(1,10):
    tfs |= set(product(['3', '5', '7'], repeat=i))

cnt = 0
for l in tfs:
    if ('3' in l) and ('5' in l) and ('7' in l):
        num = int(''.join(l))
        if num <= n:
            cnt += 1
print(cnt)

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
d=deque([3,5,7])


ans=0

while d:
    tmp=d.popleft()
    if tmp<=n:
        s=Counter(str(tmp))
        if s["3"] and s["5"] and s["7"]:
            
            ans+=1
        d.append(tmp*10+3)
        d.append(tmp*10+5)
        d.append(tmp*10+7)

print(ans)

Solution (Python):
ls=[]
def rec(n):
    if len(str(n))>9: return
    ls.append(n)
    for i in [3,5,7]: rec(10*n+i)
n=int(input())
rec(0)
cnt=0
for l in ls:
    if l<=n and all(str(l).count(i)>0 for i in "357"): cnt+=1
print(cnt)

Solution (Python):
from collections import Counter
ls=[]
def rec(n):
    if len(str(n))>9: return
    ls.append(n)
    rec(n*10+3)
    rec(n*10+5)
    rec(n*10+7)
n=int(input())
rec(3)
rec(5)
rec(7)
cnt=0
for l in ls:
    temp=Counter(str(l))
    if l<=n and len(temp.keys())==3:
        cnt+=1
print(cnt)

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

L = len(str(N))

import math
import itertools

ans = 0

for now_L in range(3, L):
    for a in list(itertools.product([3,5,7], repeat=now_L)):
        num = int("".join(map(str, a)))

        if set(a) == set([3,5,7]):
            ans += 1
        
for a in list(itertools.product([3,5,7], repeat=L)):
    num = int("".join(map(str, a)))
    if num > N:
        break

    if set(a) == set([3,5,7]):
        ans += 1

print(ans)

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


def dfs(s:str) -> int: 
    
    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 deque

n = int(input())

d = deque([3, 5, 7])
res = 0
while True:
    v = d.popleft()
    if v > n:
        break
    if len(set(str(v))) == 3:
        res += 1
    d.append(v * 10 + 3)
    d.append(v * 10 + 5)
    d.append(v * 10 + 7)

print(res)

Solution (Python):
def dfs(li):
    if int("".join(li)) > N:
        return 0
    cnt = 1 if all(i in li for i in "357") else 0
    for i in "357":
        cnt += dfs(li + [i])
    return cnt


N = int(input())
print(dfs(["0"]))

Solution (Python):
def dfs(li, cnt, digits):
    if len(li) == digits:
        n = int("".join(li))
        if n <= N and all(i in li for i in ("3", "5", "7")):
            cnt += 1
        return cnt
    for i in ("3", "5", "7"):
        cnt = dfs(li + [i], cnt, digits)
    return cnt


N = int(input())
ans = sum(dfs([], 0, i) for i in range(1, len(str(N)) + 1))
print(ans)

Solution (Python):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    N = int(input())
    que = deque(["3", "5", "7"])
    ans = 0
    while True:
        i = que.popleft()
        if int(i) > N:
            break
        if "3" in i and "5" in i and "7" in i:
            ans += 1
        que.append(i + "3")
        que.append(i + "5")
        que.append(i + "7")
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import itertools

n = int(input())

must = set(["3", "5", "7"])
count = 0

for i in itertools.product("0357", repeat=10):
    num = int("".join(i))
    set_ = set(list(str(num)))
    if 0 in set_:
        continue
    if set_ != must:
        continue

    if int("".join(i)) <= n:
        
        count += 1
    else:
        break
print(count)

Solution (Python):
import collections
import sys
sys.setrecursionlimit(10**6)
dd = collections.defaultdict(int)
def dfs(i,n):
    if(i<=n):
        k = [0,0,0]
        for j in range(len(str(i))):
            if(int(str(i)[j])==3):
                k[0]=1
            if(int(str(i)[j])==5):
                k[1]=1
            if(int(str(i)[j])==7):
                k[2]=1
        if 0 not in k:
            dd[i]=1
        dfs(int(str(i)+"3"),n)
        dfs(int(str(i)+"5"),n)
        dfs(int(str(i)+"7"),n)


def main():
    n = int(input())
    res = 0
    a = [3,5,7]
    for i in a:
        dfs(i,n)
    for key in dd.keys():
        res+=1
    print(res)
    

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
lim=len(str(n))
cand=[3,5,7]
ans=[]
while cand:
    i=cand.pop()
    for j in [3,5,7]:
        k=int(str(i)+str(j))
        if k<=n:
            cand.append(k)
            if len(set(str(k)))==3:
                ans.append(k)
print(len(ans))

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

ans = 0
ls = ['3','5','7']
for x in ls:
    st = deque([])
    flag = False
    st.append((x, flag))
    while st:
        cur, f = st.pop()
        if f:
            ans += 1
        else:
            if '3' in set(list(cur)) and '5' in set(list(cur)) and '7' in set(list(cur)):
                
                f = True
                ans += 1
        for y in ls:
            if int(cur + y) <= N:
                st.append((cur+y, f))
print(ans)

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

ans = 0
ls = ['3','5','7']
for x in ls:
    st = deque([])
    flag = False
    st.append((x, flag))
    while st:
        cur, f = st.pop()
        if f:
            ans += 1
        else:
            if '3' in set(list(cur)) and '5' in set(list(cur)) and '7' in set(list(cur)):
                
                f = True
                ans += 1
        for y in ls:
            if int(cur + y) <= N:
                st.append((cur+y, f))
print(ans)

Solution (Python):
from itertools import product
n=int(input())
a=[]
for i in range(3,10):
  a+=(list(product('357',repeat=i)))
cnt=0
for i in a:
  if len(set(i))!=3:
    continue
  if int(''.join(list(i)))<=n:
    cnt+=1
  else:break
print(cnt)

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

cands = set()

def dfs(n, c3, c5, c7):
    if c3 >= 1 and c5 >= 1 and c7 >= 1:
        cands.add(n)
    if n >= 10 ** 9:
        return
    dfs(n * 10 + 3, c3 + 1, c5, c7)
    dfs(n * 10 + 5, c3, c5 + 1, c7)
    dfs(n * 10 + 7, c3, c5, c7 + 1)

dfs(0, 0, 0, 0)
print(len([c for c in cands if c <= n]))

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

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

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)

import numpy as np
L = []
for n in range(3, 10):
    for i in range(3**n):
        i3 = Base_10_to_n(i, 3).zfill(n)
        num = ''
        for j in range(n):
            if i3[j] == '0':
                num += '3'
            elif i3[j] == '1':
                num += '5'
            elif i3[j] == '2':
                num += '7'
        if '3' in num and '5' in num and '7' in num:
            L.append(int(num))
L = np.array(L)

print(np.count_nonzero(L[L<=N]))

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

Solution (Python):
from itertools import product
n = int(input())
ans = 0
for l in range(1, 10):
    for b in product('753', repeat=l):
        if len(set(iter(b))) == 3 and int(''.join(b)) <= n:
            ans += 1
print(ans)

Solution (Python):
n = int(input())
B = []
def dfs(A):
  x = int(''.join(A))
  if x <= n:
    if '7' in A and '5' in A and '3' in A:
      B.append(x)
    dfs(A + ['7'])
    dfs(A + ['5'])
    dfs(A + ['3'])

dfs(['0'])
print(len(B))

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())
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):
def f(L,X=[]):
    if L==1:
        return ["3","5","7"]
    else:
        X=f(L-1)
        Y=[]
        for x in X:
            Y+=[x+"3",x+"5",x+"7"]
        return Y
    
N=int(input())
G=[]
for k in range(1,10):
    V=f(k)
    
    for v in V:
        if ("3" in v) and ("5" in v) and ("7" in v):
            G.append(int(v))

T=0
for x in G:
    if x<=N:
        T+=1

print(T)

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


def dfs(curr_num, e753, list753, n):
    if curr_num > n: return
    if e753 == 7:
        list753.append(curr_num)
    dfs(curr_num*10+7, e753|4, list753, n)
    dfs(curr_num*10+5, e753|2, list753, n)
    dfs(curr_num*10+3, e753|1, list753, n)


def main():
    n = int(input())
    list753 = []
    dfs(0,0,list753,n)
    print(len(list753))


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import product

n = int(input())
n_len = len(str(n))
ans = 0
for i in range(3,n_len):
    ite = product(range(3),repeat=i)
    for it in ite:
        if 0 in it and 1 in it and 2 in it:
            ans += 1


num_d = {0:7,1:5,2:3}
ite = product(range(3),repeat=n_len)
for it in ite:
    if 0 in it and 1 in it and 2 in it:
        curr_num = 0
        for i,j in enumerate(it):
            curr_num += num_d[j]*(10**(n_len-1-i))
        if curr_num <= n: 
            ans+=1

print(ans)

Solution (Python):
ns = input()

dp = [ [ [0]*8  for _ in range(2) ] for _ in range(len(ns)) ]


first = int(ns[0])
if first > 7:
    dp[0][1][4] = 1
    dp[0][1][2] = 1
    dp[0][1][1] = 1
elif first == 7:
    dp[0][0][4] = 1
    dp[0][1][2] = 1
    dp[0][1][1] = 1
elif first > 5:
    dp[0][1][2] = 1
    dp[0][1][1] = 1
elif first == 5:
    dp[0][0][2] = 1
    dp[0][1][1] = 1
elif first > 3:
    dp[0][1][1] = 1
elif first == 3:
    dp[0][0][1] = 1
dp[0][1][0] = 1

for i in range(0, len(ns)-1):
    next_num = int(ns[i+1])
    dp[i+1][1][0] += dp[i][1][0] 
    for e753 in range(8):
        dp[i+1][1][e753 | 4] += dp[i][1][e753] 
        dp[i+1][1][e753 | 2] += dp[i][1][e753] 
        dp[i+1][1][e753 | 1] += dp[i][1][e753] 

        if next_num > 7:
            dp[i+1][1][e753 | 4] += dp[i][0][e753] 
        if next_num > 5:
            dp[i+1][1][e753 | 2] += dp[i][0][e753] 
        if next_num > 3:
            dp[i+1][1][e753 | 1] += dp[i][0][e753]

        if next_num == 7:
            dp[i+1][0][e753 | 4] += dp[i][0][e753] 
        if next_num == 5:
            dp[i+1][0][e753 | 2] += dp[i][0][e753] 
        if next_num == 3:
            dp[i+1][0][e753 | 1] += dp[i][0][e753]

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

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())
num=[3,5,7]
def dfs(s):
    if s>N:
        return 0
    a=str(s)
    if a.count("3")>=1 and a.count("5")>=1 and a.count("7")>=1:
        ret=1
    else:
        ret=0
    for i in num:
        ret+=dfs(10*s+i)
    return ret
print(dfs(0))

Solution (Python):
from itertools import product
from bisect import bisect_right
def main():
    n = int(input())
    n_753 = []
    for i in range(3, 10):
        for s in product(['3', '5', '7'], repeat = i):
            if len(set(s)) != 3:
                continue
            n_753.append(int(''.join(s)))
    n_753.sort()
    print(bisect_right(n_753, n))
if __name__ == '__main__':
    main()

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

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

print(ct('0'))

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())
lis = ["3","5","7"]
i = 0
while i < 9:
    X = []
    for L in lis:
        if int(L) < 10**(i):
            pass
        else:
            x3 = "".join([L]+["3"])
            X.append(x3)
            x5 = "".join([L]+["5"])
            X.append(x5)
            x7 = "".join([L]+["7"])
            X.append(x7)
    i += 1
    for x in X:
        lis.append(x)
lis2 = []
for A in lis:
    if "3" in A:
        if "5" in A:
            if "7" in A:
                lis2.append(A)
for i in range(len(lis2)):
    lis2[i] = int(lis2[i])
lis2 = sorted(lis2)
ans = 0
for A in lis2:
    if int(A) > n:
        break
    else:
        ans += 1
print(ans)

Solution (Python):
from collections import deque

n = int(input())
L = []
li = ['3', '5', '7']
que = deque(li)
while que:
    num = que.popleft()
    for i in range(3):
        nn = num + li[i]
        L.append(nn)
        if int(nn) < 10 ** 9:
            que.append(nn)
ans = 0
for num in L:
    if int(num) > n:
        break
    elif all(i in num for i in li):
        ans += 1
print(ans)

Solution (Python):
n=int(input())
list_num = [3, 5, 7]
result=[]
def dfs(val):
  if val > n:
    return

  result.append(val)

  for i in list_num:
    dfs(val*10+i)

dfs(0)
count = 0
for i in result:
  str_num = str(i)

  if str_num.count('3') == 0:
    continue
  if str_num.count('5') == 0:
    continue
  if str_num.count('7') == 0:
    continue
  count += 1

print(count)

Solution (Python):
N=int(input())
ans=0
for i in range((3**10-1)//2):
 Sui=[0]*9
 for j in range(9):
  if i==0:
   Sui[j]=0
  elif i%3==0:
   Sui[j]=3
   i-=3
  elif i%3==1:
   Sui[j]=5
   i-=1
  else:
   Sui[j]=7
   i-=2
  i=i//3
 if 3 in Sui and 5 in Sui and 7 in Sui:
  b=0
  for j in range(9):
   b+=Sui[j]*(10**j)
  if b<=N:
   ans+=1
print(ans)

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

N = int(input())
V = [3, 5, 7]

li = []


def rec(curr, use):
    if curr > N:
        return
    if use == 0b111:
        li.append(curr)
    for i, b in enumerate(V):
        rec(curr * 10 + b, use | max(1, i * 2))


rec(0, 0)

print(len(li))

Solution (Python):





import math
import sys
import bisect
import heapq  
from collections import deque

inf = 10**18
mod = 10**9+7

n = list(map(int, list(input())))
def getAns(now , giri, t,f,s):
    if now == len(n):
        if t and f and s:
            return 1
        else:
            return 0
    tmp = n[now]
    ret = 0
    if giri:
        if tmp > 7:
            ret += getAns(now+1, False, t, f, True)
            ret += getAns(now+1, False, t, True, s)
            ret += getAns(now+1, False, True, f, s)
        elif tmp == 7:
            ret += getAns(now+1, giri, t, f, True)
            ret += getAns(now+1, False, True, f, s)
            ret += getAns(now+1, False, t, True, s)
        elif tmp > 5:
            ret += getAns(now + 1, False, True, f, s)
            ret += getAns(now + 1, False, t, True, s)
        elif tmp == 5:
            ret += getAns(now + 1, False, True, f, s)
            ret += getAns(now + 1, giri, t, True, s)
        elif tmp > 3:
            ret += getAns(now + 1, False, True, f, s)
        elif tmp == 3:
            ret += getAns(now + 1, giri, True, f, s)
    else:
        ret+=getAns(now+1, giri, t,f,True)
        ret+=getAns(now+1, giri, t,True,s)
        ret+=getAns(now+1, giri, True, f, s)
    return ret

ans = 0
for i in range(len(n)-1):
    ans += getAns(i+1,False,False,False,False)
print(ans + getAns(0,True,False,False,False))

Solution (Python):
def is_753(n):
    n = str(n)
    return(n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1)


n = int(input())


v = [7, 5, 3]
li = []
prev = [7, 5, 3]

for i in range(9):
    tmp = []
    for j in v:
        for k in prev:
            tmp.append(k * 10 + j)
    prev = tmp
    li = li + prev

li = [x for x in li if is_753(x) and x <= n]

print(len(li))

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

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

print(dfs('0'))

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
LET=('3','5','7')
n=int(input())

def dfs(s):
  cnt = 0
  if len(s) >0 and int(s) > n:
    return cnt
  if s.count('3') > 0 and s.count('5')>0 and s.count('7')>0:
    cnt += 1
  for l in LET:
    cnt += dfs(s+l)
  return cnt

print(dfs(''))

Solution (Python):
from collections import deque
n = int(input())
num753 = set()
q = deque([3,5,7])


while q:

    
    x = q.pop()

    
    if x <= 10**9:

        
        num753.add(x)

        
        q.append(x*10+3)
        q.append(x*10+5)
        q.append(x*10+7)
count = 0


for i in num753:
    if i <= n:
        lst = list(str(i))
        if "3" in lst and "5" in lst and "7" in lst:
            count += 1

print(count)

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

q = ["3", "5", "7"]
ans = 0
while q:
    now = q.pop(0)
    if int(now) <= N:
        for c in ("3", "5", "7"):
            q.append(now + c)
        if len(set(now)) == 3:
            ans += 1

print(ans)

Solution (Python):
from itertools import product
N = int(input())
STR_N = str(N)
all_pat =[]
for i in range(3,len(STR_N)+1):
    pattern = list(product(["7","5","3"],repeat=i))
    for p in pattern:
        if len(set(p))==3:
            all_pat.append(int(''.join(p)))
all_pat = list(set(all_pat))
all_pat.sort()
cnt = 0
for a in all_pat:
    if a<=N:
        cnt+=1
print(cnt)

Solution (Python):
strn = input()
n = int(strn)
shichigolist = ["3","5","7"]
shichigo = [[] for _ in range(len(strn))]
for i in range(len(strn)):
	if i == 0:
		for j in shichigolist:
			shichigo[i].append(j)
	else:
		for j in shichigo[i-1]:
			for k in shichigolist:
				shichigo[i].append(j+k)
target = len(strn)-1
for i in range(len(strn)):
	for j in shichigo[i][:]:
		if i == target:
			if int(j) > n:
				shichigo[target].remove(j)
			elif j.count("3")==0 or j.count("5")==0 or j.count("7")==0:
				shichigo[target].remove(j)
		else:
			if j.count("3")==0 or j.count("5")==0 or j.count("7")==0:
				shichigo[i].remove(j)

print(sum([len(shichigo[i]) for i in range(len(strn))]))

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

Solution (Python):
from collections import Counter

N = int(input())
N_list = list(str(N))
number = ['3', '5', '7']
count = 0

def iter_p_adic(p, n):
    from itertools import product
    tmp = [range(p)] * n
    return product(*tmp)

for i in range(len(N_list)):
    iterator = iter_p_adic(3, i+1)
    for idxs in iterator:
        num = []
        for j in range(i+1):
            num.append(number[idxs[j]])
        n = int(''.join(num))
        if len(list(Counter(num))) == 3 and n <= N:
            count += 1

print(count)

Solution (Python):
import collections
n = int(input())
dic = collections.defaultdict(int)
ans = 0
if n < 357:
    print(0)
else:
    ls = ["357","375","537","573","735","753"]
    ls_next = []
    for i in range(len(ls)):
        if int(ls[i]) <= n:
            ls_next.append(ls[i])
    ls = ls_next
    ans += len(ls_next)
    for i in range(10):
        ls_next = []
        for j in range(len(ls)):
            for k in range(len(ls[0])):
                if int(ls[j][:k]+"3"+ls[j][k:]) <= n:
                    ls_next.append(ls[j][:k]+"3"+ls[j][k:])
                if int(ls[j][:k]+"5"+ls[j][k:]) <= n:
                    ls_next.append(ls[j][:k]+"5"+ls[j][k:])
                if int(ls[j][:k]+"7"+ls[j][k:]) <= n:
                    ls_next.append(ls[j][:k]+"7"+ls[j][k:])
        for j in range(len(ls_next)):
            dic[ls_next[j]] = 1
        ls_next = list(dic.keys())
        
        if len(ls_next) == 0:
            break

        ans += len(ls_next)
        ls = ls_next
        dic.clear()
    print(ans)