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):
def function(n):
    digit=len(str(n))
    N=str(n)
    if digit<3:
        return 0
    else:
        k=int(N[0])
        m=int(N[1])
        if k<3:
            return function(10**(digit-1)-1)
        elif k==3 and m>0:
            return function(10**(digit-1)-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(5,7,n%(10**(digit-1)))
        elif k==3 and m==0:
            return function(10**(digit-1)-1)
        elif k==4:
            return function(4*(10**(digit-1))-1)
        elif k==5 and m>0:
            return function(4*(10**(digit-1))-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(3,7,n%(10**(digit-1)))
        elif k==5 and m==0:
            return function(4*(10**(digit-1))-1)
        elif k==6:
            return function(6*(10**(digit-1))-1)
        elif k==7 and m>0:
            return function(6*(10**(digit-1))-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(3,5,n%(10**(digit-1)))
        elif k==7 and m==0:
            return function(6*(10**(digit-1))-1)
        else:
            return function(8*(10**(digit-1))-1)

def subfunction(a,b,n):
    digit=len(str(n))
    N=str(n)
    k=int(N[0])
    if digit<2:
        return 0
    else:
        if k<a:
            return 0
        elif k==a:
            if n%(10**(digit-1))<b*(10**(digit-1)-1)//9:
                s=0
            else:
                s=1
            return subfunction(a,b,n%(10**(digit-1)))+s
        elif a<k<b:
            return subfunction(a,b,(a+1)*(10**(digit-1))-1)
        elif k==b:
            if n%(10**(digit-1))<a*(10**(digit-1)-1)//9:
                s=0
            else:
                s=1
            return subfunction(a,b,(a+1)*(10**(digit-1))-1)+subfunction(a,b,n%(10**(digit-1)))+s
        else:
            return subfunction(a,b,(b+1)*(10**(digit-1))-1)

N=int(input())
print(function(N))

Solution (Python):
n = int(input())
ans = 0
def bfs(x):
    global ans
    if x>n: return 0
    else:
        if set(list(str(x)))=={'7','5','3'}:
            ans+=1
        bfs(x*10+3)
        bfs(x*10+5)
        bfs(x*10+7)
bfs(0)
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = input()
    n_len = len(N)

    def dfs(val, is357):
        c = 0

        if (not is357
            and val.count('3') > 0
            and val.count('5') > 0
            and val.count('7') > 0):
            is357 = True

        if len(val) == n_len:
            if is357 and int(val) <= int(N):
                return 1
            else:
                return 0

        if is357:
            c+= 1

        c += dfs(val + '3', is357)
        c += dfs(val + '5', is357)
        c += dfs(val + '7', is357)
        return c

    print(dfs('', False))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり整数
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''


N = int(input())


ans = []

for keta in range(3,10):
    for bit in range(3**keta): 

        temp = 0
        check = [False, False, False]
        for k in range(keta):
            where = bit%(3**(k+1))//(3**k)
            temp += (where*2+3)*(10**k)
            check[where] = True
        
        if all(check):
            ans.append(temp)

ans.sort()
idx = bisect.bisect_right(ans, N)
print(idx)

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


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

        for z in '753':
            out += d(s + z)

        return out


print(d('0'))

Solution (Python):
def sigm(nk):
    s=3**3*(3**(nk-2)-1)/(3-1)
    s=s-3*2**3*(2**(nk-2)-1)/(2-1)
    s=s+(nk-2)*3
    return int(s)
    
n=int(input())

if n<357:
    print(0)
else:
    x0=[357,375,537,573,735,753]
    x1=[3,5,7]
    m=0
    nk=len(str(n))
    if nk==3:
        for j in range(6):
            x=x0[j] 

            if x<=n:
                m=m+1
    else:
        m=sigm(nk-1)
        for i in range(3**nk):
            ii=i
            x=0
            for j in range(nk):
                iii=ii//3
                ir=ii-iii*3
                ii=(ii-ir)//3
                x=x+int(x1[ir])*10**j
            xstr=str(x)
            if xstr.find("3")>=0 and xstr.find("5")>=0 and xstr.find("7")>=0 and n>=x:
                m=m+1                 
    print(m)

Solution (Python):

s = input()
n = int(s)
keta = len(s)

dp = [
    [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
    for _ in range(keta + 1)
]
dp[0][0][0][0][0] = 1
kazu = [0, 3, 5, 7]
for i in range(keta):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                for smaller in range(2):
                    nd = int(s[i])
                    for d in range(10):
                        ni = i + 1
                        nj = j
                        nk = k
                        nl = l
                        nsmaller = smaller
                        if d not in kazu:
                            continue
                        if d == 3:
                            nj = 1
                        if d == 5:
                            nk = 1
                        if d == 7:
                            nl = 1
                        if smaller == 0:
                            if d > nd:
                                continue
                            if d < nd:
                                nsmaller = 1
                        if d == 0:
                            if nj + nk + nl != 0:
                                continue
                        dp[ni][nj][nk][nl][nsmaller] += dp[i][j][k][l][smaller]
print(dp[keta][1][1][1][0] + dp[keta][1][1][1][1])

Solution (Python):
from itertools import product
n=int(input())
cnt=0
kazu=[3,5,7]
for j in range(3,10):
    kumiawase = list(product(kazu, repeat=j))
    for kumi in kumiawase:
        suuji=''
        for moji in kumi:
            suuji+=str(moji)
        if '3'  not in suuji:
            continue
        if '5'  not in suuji:
            continue
        if '7'  not in suuji:
            continue
        hantei=int(suuji)
        if hantei <=n:
            cnt+=1
print(cnt)

Solution (Python):
from itertools import product
n=int(input())
ans = 0
for i in range(3,len(str(n))+1):
    for num in product(('3','5','7'),repeat=i):
        if len(set(num)) == 3 and int("".join(num)) <= n:
            ans += 1
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
    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())

check = 0b000
s = [3,5,7]

ans = 0


def rec(now,check):
    global ans

    if now > n :
        return 0

    if check == 0b111:
        ans+=1

    rec(now*10 +3 ,check | (1<<0))
    rec(now*10+5,check | (1<<1))
    rec(now*10+7,check | (1<<2))



rec(0,0b000)

print(ans)

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

def solve(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 += solve(s + c)

  return ret

print(solve('0'))

Solution (Python):

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

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

Solution (Python):
def words(n):
    if n==1:return "357"
    A=[]
    for i in "357":
        for j in words(n-1):
            A.append(i+j)
    return A


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

cnt=0
for j in range(3,m+1):
    for i in words(j):
        if n>=int(i) and ("3" in i and "5" in i and "7" in i):
            cnt +=1

print(cnt)

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


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


print(dfs('0'))

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


def dfs(ans, r, stop):
    if len(str(ans)) == stop:
        if ans <= n:
            if "3" in str(ans) and "5" in str(ans) and "7" in str(ans):
                return 1
            else:
                return 0
        else:
            return 0

    ret = [dfs(ans * 10 + j, r + 1, stop) for j in (3, 5, 7,)]

    return sum(ret)


x = 0
for i in range(3, R+1):
    x += dfs(0, 0, i)

print(x)

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

def ans(s):
    if int(s) > N:
        return 0
    else:
        cnt = int(s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0) 
        return ans(s+"3") + ans(s+"5") + ans(s+"7") + cnt 
    
print(ans("0"))

Solution (Python):
n = int(input())
cand = list("357")
stk = ["0"]
ans = 0
while stk:
    tmp = stk.pop()
    if len(tmp)==10:
        if 0<int(tmp)<=n and tmp.count("3") and tmp.count("5") and tmp.count("7"):
            ans += 1
    else:
        if int(tmp)==0: stk.append(tmp+"0")
        for i in cand: stk.append(tmp+i)
print(ans)

Solution (Python):
import itertools
N=int(input())
ans=0
S=[]
for i in range(10):
    S+=list(itertools.product("357",repeat=i))
for s in S:
    if len(set(s))>2 and int("".join(s))<=N:
        ans+=1
print(ans)

Solution (Python):
n = int(input())
s = '753'

stack = ['']
cnt = 0
while stack:
    t = stack.pop()
    for c in s:
        u = t + c
        if int(u) <= n:
            if '7' in u and '5' in u and '3' in u:
                
                cnt += 1
            stack.append(u)
print(cnt)

Solution (Python):
import itertools
def main():
    N = int(input())
    if N < 357:
        print(0)
    else:
        digit = 1
        n = N
        while N//10 != 0:
            N //= 10
            digit += 1
        ans = 0
        for i in range(3,digit+1):
            ls = list(itertools.product([3,5,7],repeat=i))
            for j in ls:
                if 3 in j and 5 in j and 7 in j:
                    tmp = 0
                    for k in range(1,len(j)+1):
                        tmp += j[-k]*10**(k-1)
                    if tmp <= n:
                        ans += 1
        print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools as it
n = int(input())
ans = 0
for i in range(len(str(n))+1):
    for p in it.product('357', repeat=i):
        if set(p) == {'3', '5', '7'} and int(''.join(p)) <= n:
            ans += 1
print(ans)

Solution (Python):
"""
from itertools import product
n = input()
ans = 0

for i in range(3,len(n)+1):
    for p in product("357",repeat=i):
        if int("".join(list(p))) > int(n): continue
        if p.count("3")*p.count("5")*p.count("7") != 0: ans += 1

print(ans)
"""

n = int(input())

def bfs(x):
    if int(x) > n: return 0
    cnt = 0
    if x.count("3")*x.count("5")*x.count("7") != 0: cnt = 1
    return cnt + bfs(x+"3") + bfs(x+"5") + bfs(x+"7")

print(bfs("0"))

Solution (Python):
from itertools import product
n = input()
ans = 0

for i in range(3,len(n)+1):
    for p in product("357",repeat=i):
        if int("".join(list(p))) > int(n): continue
        if p.count("3")*p.count("5")*p.count("7") != 0: ans += 1

print(ans)

Solution (Python):
from itertools import product
N=int(input())
a=0
for i in range(3,10):
    l=list(product([3,5,7],repeat=i))
    for j in l:
        if 3 in j and 5 in j and 7 in j:
            t=0
            for k in range(i):
                t+=j[k]*10**k
            if t<=N:
                a+=1
print(a)

Solution (Python):
n = input()
import itertools as it
print(sum(len(set(p))>2 and int(''.join(p))<=int(n) for i in range(len(n)+1) for p in it.product('357',repeat=i)))

Solution (Python):
n = int(input())
import itertools as it
ans = 0
for i in range(11):
  for p in it.product(*['357']*i):
    if len(set(p))>2 and int(''.join(p))<=n:
      ans += 1
print(ans)

Solution (Python):
n = int(input())
import itertools as it
ans = 0
for i in range(len(str(n))+1):
  for p in it.product('357',repeat=i):
    if set(p)=={'3','5','7'} and int(''.join(p))<=n:
      ans += 1
print(ans)

Solution (Python):
import sys

N = int(input())

def search(n, ans):
    if n > N:
        return ans
    if ('3' in str(n)) and ('5' in str(n)) and ('7' in str(n)):
        ans += 1
    ans = search(int(str(n)+'3'),ans)
    ans = search(int(str(n)+'5'),ans)
    ans = search(int(str(n)+'7'),ans)
    return ans

print(search(0, 0))

Solution (Python):
n=input()
def dfs(s):
  if int(s)>int(n):
    return 0
  cnt=1 if all(s.count(i) for i in '753') else 0
  for j in '753':
    cnt+=dfs(s+j)
  return cnt
print(dfs('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):
import itertools
import bisect

n = int(input())
m = len(str(n))
li = []

for i in range(3,m+1):
    li_tmp = list(itertools.product([3,5,7], repeat = i))
    for j in li_tmp:
        if 3 in j and 5 in j and 7 in j:
            a = 0
            for k in range(i):
                a += j[k] * 10**(i-k-1)
            li.append(a)

print(bisect.bisect(li, n))

Solution (Python):
from sys import setrecursionlimit

setrecursionlimit(10**6)
def recur(N_:int,limit:int):
    if N_ > limit:
        return 0
    else:
        tmp = str(N_)
        if ("3" in tmp) and ("5" in tmp) and ("7" in tmp):
            N_ *= 10
            return recur(N_ + 3,limit) + recur(N_ + 5,limit) + recur(N_ + 7,limit) + 1
        else:
            N_ *= 10
            return recur(N_ + 3,limit) + recur(N_ + 5,limit) + recur(N_ + 7,limit)


def main():
    N = int(input())
    ans = recur(3,N) + recur(5,N) + recur(7,N)
    print(ans)
    return   

if __name__ == "__main__":
    main()

Solution (Python):
import itertools

n=input()

c=[]
for i in range(3,len(n)+1):
    c += list(itertools.product([3,5,7], repeat=i))

m=int(n)
ans=0
for i in range(len(c)):
    if 3 in c[i] and 5 in c[i] and 7 in c[i]:
        search=""
        for g in range(len(c[i])):
            search+=str(c[i][g])
        if m>=int(search):
            ans+=1
print(ans)

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

def dfs(cur, use):
  global counter

  if cur > N:
    return

  if use == 0b111:
    counter += 1

  dfs(cur * 10 + 7, use | 0b001)
  dfs(cur * 10 + 5, use | 0b010)
  dfs(cur * 10 + 3, use | 0b100)

dfs(0, 0b000)
print(counter)

Solution (Python):


N=int(input())


cand=[]
def saiki(num,arc):
    if "3" in arc and "5" in arc and "7" in arc:
        cand.append(arc)
    if num==len(str(N)):
        return 0
    else:
        for item in ["3","5","7"]:
            saiki(num+1,arc+[item])
    return 0


saiki(0,[])

ans=0
for item in cand:
    if N>=((int("".join(item)))):
        ans+=1
        
print(ans)

Solution (Python):
import itertools as it
n=int(input())
ans=0
for nn in range(3,10):
    l=[ i for i in it.product(['3','5','7'], repeat=nn)]
    for ll in l:
        if int(''.join(ll)) <= n:
            if len(set(ll)) ==3:
                ans+=1

print(ans)

Solution (Python):
import itertools

N=int(input())
num=[3,5,7]
dig=10
p=[1]*dig
for i in range(dig-1):
    p[i+1]=p[i]*10
    
ans=0

def check(n):
    strn=str(n)
    for i in range(len(num)):
        if not (str(num[i]) in strn):
            return False
    return True
        
ans=0
flag=1
for d in range(3,dig):
    if flag==0:
        break
    for pro in itertools.product(num, repeat=d):
        temp=0
        for j in range(d):
            temp+=pro[-1-j]*p[j]
        if temp>N:
            flag=0
            break
        if check(temp):
            ans+=1
        
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
ans = 0

def func(num):
    global ans
    if num > n:
        return 0

    nnn = list(str(num))
    key = Counter(nnn).keys()
    if len(key) == 3:
        if '3' in key:
            if '5' in key:
                if '7' in key:
                    ans += 1

    func(10 * num + 3)
    func(10 * num + 5)
    func(10 * num + 7)

func(0)
print(ans)

Solution (Python):

import math

N = int(input())





def search_max(under_list,ans):
    next_list = []
    top_multiplication = 10**(int(math.log10(under_list[0]))+1)
    
    for i in [3,5,7]:
        for j in under_list:
            number = i*top_multiplication + j
            
            if N >= number:
                next_list.append(number)
                
                
                set_number = set((str(number))) 
                if "3" in set_number and "5" in set_number and  "7" in set_number:
                    ans += 1
                    
            else:
                
                return ans
    
    
    return search_max(next_list,ans)

if N < 357:
    print(0)
else:
    under_list = [3,5,7]
    ans = search_max(under_list,0)
    print(ans)

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

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

m = len(str(n))

from itertools import product
nums = ['3', '7', '5']

ans = 0
for i in range(3, m+1):
   a = list(product(nums, repeat=i))
   b = [int(''.join(list(j))) for j in a if ('3' in j and '5' in j and '7' in j)]
   if (i == m):
      ans += len([k for k in b if k <= n])
   else:
      ans += len(b)

print(ans)

Solution (Python):
from itertools import product
n=int(input())
cnt=0
suuji=[3,5,7]
set_s=set(suuji)
kazu=[]
for i in range(len(str(n))+1):
    kumiawase=list(product(suuji, repeat=i))
    for kumi in kumiawase:
        if set(kumi)==set_s and n >=int(''.join(list(map(str,kumi)))):
            cnt+=1
print(cnt)

Solution (Python):

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



s = int(input())
ans = 0
digit = 0
for j in range(10):
    i = j+1
    if s >= 10**i: pass
    else: break
    digit = i+1
if digit == 0: digit += 1


num = [3,5,7]
flag = [0,0,0]
for dig in range(1,digit+1):
    for i in range(3**dig):
        val = 0
        tmp = i
        for j in range(dig):
            if flag[tmp % 3] == 0: flag[tmp%3] = 1
            val += num[tmp % 3]*(10**j)
            tmp = tmp // 3
        
        if val <= s and flag[0]*flag[1]*flag[2] ==1:
            ans += 1
            
        flag = [0,0,0]
print(ans)

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

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

Solution (Python):
from collections import Counter

N = int(input())

def solve(str_num):
    ans = 0
    if int(str_num or 0) <= N:
        if len(Counter(str_num)) == 3:
            ans += 1
        for n in ("3","5","7"):
            ans += solve(str_num+n)
    return ans

print(solve(""))

Solution (Python):
n = int(input())
ans = []
count = 0
def dfs(s):

    if int(s)>n:
        return 0
    ans.append(s)
    for c in '753':
        dfs(s+c)
dfs('0')
for i in ans:
    if all(i.count(j)>0 for j in '753'):
        count += 1
print(count)

Solution (Python):
from itertools import product


def main():
    N = int(input())
    result = 0
    numbers = ["3", "5", "7"]
    for i in range(3, len(str(N)) + 1):
        for p in product(numbers, repeat=i):
            flag = True
            tmp = "".join(p)
            for n in numbers:
                if n in tmp:
                    continue
                else:
                    flag = False
            if flag:
                if int(tmp) <= N:
                    result += 1
    print(result)


if __name__ == '__main__':
    main()

Solution (Python):


def dfs(n,s):
    if int(s)>n:
        return 0
    res=0
    if s.count('7')>0 and s.count('5')>0 and s.count('3')>0:
        res=1
    
    for i in '753':
        res+=dfs(n,s+i)
    return res

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

Solution (Python):



n=int(input())

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

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

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

    return cnt

print(dfs('0'))

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

Solution (Python):

import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

N = 0
ans = 0
def rec(n):
    global ans
    if n > N:
        return
    m = _collections.defaultdict(int)
    for i in sorted(str(n)):
        m[i] += 1
    if m["3"] > 0 and m["5"] > 0 and m["7"] > 0:
        ans += 1
    rec(n * 10 + 3)
    rec(n * 10 + 5)
    rec(n * 10 + 7)

def main():
    global N
    N = cin.int()
    rec(3)
    rec(5)
    rec(7)
    print(ans)
    return
if __name__ == "__main__":
    main()

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


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


print(dfs('0'))

Solution (Python):
N = input()

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

dp[0][0][0] = 1

for i in range(len(N)):
    for j in range(2):
        D = 9 if j else int(N[i])
        for d in [x for x in [3, 5, 7] if x <= D]:
            if d == 3:
                dp[i + 1][j | (d < D)][1] += dp[i][j][0] + dp[i][j][1]
                dp[i + 1][j | (d < D)][3] += dp[i][j][2] + dp[i][j][3]
                dp[i + 1][j | (d < D)][5] += dp[i][j][4] + dp[i][j][5]
                dp[i + 1][j | (d < D)][7] += dp[i][j][6] + dp[i][j][7]
            elif d == 5:
                dp[i + 1][j | (d < D)][2] += dp[i][j][0] + dp[i][j][2]
                dp[i + 1][j | (d < D)][3] += dp[i][j][1] + dp[i][j][3]
                dp[i + 1][j | (d < D)][6] += dp[i][j][4] + dp[i][j][6]
                dp[i + 1][j | (d < D)][7] += dp[i][j][5] + dp[i][j][7]
            elif d == 7:
                dp[i + 1][j | (d < D)][4] += dp[i][j][0] + dp[i][j][4]
                dp[i + 1][j | (d < D)][5] += dp[i][j][1] + dp[i][j][5]
                dp[i + 1][j | (d < D)][6] += dp[i][j][2] + dp[i][j][6]
                dp[i + 1][j | (d < D)][7] += dp[i][j][3] + dp[i][j][7]
            else:
                raise Exception("Not 3 or 5 or 7")


ans = dp[len(N)][1][7] + dp[len(N)][0][7]

sub = 0
for i in range(3, len(N)):
    sub753 = 3 ** i
    sub75 = 2 ** i
    sub += sub753 - (3 * sub75 - 3)

print(ans + sub)

Solution (Python):

import math
import heapq
import bisect
import numpy as np


N = int(input())

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

print(cnt_753('0'))

Solution (Python):
def SGS(X):
    global ans
    global N
    if X != "":
        if int(X) > N :
            return False
    if "7" in X and "5" in X and "3" in X:
        ans += 1
    SGS("3" + X)
    SGS("5" + X)
    SGS("7" + X)
    return(ans)

ans = 0
N = int(input())
print(SGS(""))

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())
sgs=['']
while len(sgs[-1])<=10:
  tmp=[]
  for s in sgs:
    for t in (list('357')+['']):
      tmp.append(t+s)
  sgs+=tmp
  sgs=list(set(sgs))
  sgs.sort()
sgs2=[]
for i in sgs:
  if len(set(list(i)))==3:
    sgs2.append(i)
sgs2.sort()
ans=0
for i in sgs2:
  if int(i)<=n:
    ans+=1
print(ans)

Solution (Python):
import itertools

N = int(input())
nums = [3, 5, 7]
num_357 = set()


candidates = []
for i in range(3, 10):
    candidates += list(itertools.product(nums, repeat=i))
for c in candidates:
    for n in nums:
        if n not in c:
            break
    else:
        
        tmp = 0
        for ind, i in enumerate(c):
            tmp += i * pow(10, ind)
        num_357.add(tmp)


ans = 0
for n_357 in num_357:
    if n_357 <= N:
        ans += 1
print(ans)

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

def dfs(s):
    if int(s) > N:
        return 0
    ans = 1 if all (s.count(c) > 0 for c in "753") else 0
    
    for c in "753":
        ans += dfs(s+c)
    return ans
print(dfs('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 '357') else 0
    for c in '357':
        ret += dfs(s + c)
    return ret


print(dfs('0'))

Solution (Python):
from itertools import product
N = int(input())
strN = str(N)
lenN = len(strN)
num = ['7','5','3']
count = 0
if N < 357:
    print(0)
else:
    for i in range(3,lenN+1):
        for j in product(num,repeat = i):
            num2 = [str(i) for i in j]
            num2 = ''.join(num2)
            if ('7' in num2) and  ('5' in num2) and  ('3' in num2) and int(num2) <= N:
                count += 1
    print(count)

Solution (Python):
import itertools
n = int(input())
l = ["7","5","3"]
c = 0
for i in range(3,10):
    for j in itertools.product(l, repeat=i):
        if len(set(j)) == 3 and int("".join(j)) <=n:
            c += 1
print(c)

Solution (Python):
def dfs(start, n, len_n):
    queue = [start]

    cnt = 0
    while queue:
        parent = queue.pop()
        for c in '357':
            cc = parent+c
            if int(cc) <= n and '3' in cc and '5' in cc and '7' in cc:
                cnt += 1
            if  len(cc) < len_n:
                queue.append(cc)
    return cnt

n = input()
len_n = len(n)
n = int(n)
print(dfs('', n, len_n))

Solution (Python):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from itertools import permutations

n = ni()

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

print(dfs('0'))

Solution (Python):
import itertools

N = int(input())

ans = 0
for d in range(3, 10):
    for p in itertools.product(["3", "5", "7"], repeat=d):
        s = "".join(p)
        if set(s) != {"3", "5", "7"}:
            continue
        if int(s) > N:
            break
        ans += 1
print(ans)

Solution (Python):
from itertools import product

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

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

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

print(dfs("0"))

Solution (Python):
N = input()

L = []
def dfs(s):
  if len(s) > 1 and int(s) >= int(N):
    return
  for c in '357':
    l = s+c
    if int(l) > int(N):
      return
    
    if '3' in l and '5' in l and '7' in l:
      L.append(int(l))
    dfs(l)
  return

dfs('')

print(len(L))

Solution (Python):
import itertools
n = list(input())
if len(n) <= 2:
    print(0)
    exit()
list3 = [1,3,9]
list2 = [1,2,4]
count = 0
for i in range(3,len(n)):
    list3.append(list3[-1]*3)
    list2.append(list2[-1]*2)
    count += list3[-1]-3*list2[-1]+3
A = ["3","5","7"]
l = list(itertools.product(A,repeat = len(n)))

for i in l:
    if "3" in i and "5" in i and "7" in i:
        if n >= list(i) :
            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):
import sys
import itertools
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    ans=0
    l=['7','5','3']
    for k in range(3,len(str(N))+1):
        for i in range(3**k):
            x=[]
            for j in range(k):
                x+=l[(i//(3**j))%3]
            if '7' in x and '5' in x and '3' in x:
                x=int(''.join(x))
                if x <= N: ans+=1
    print(ans)

if __name__ == '__main__':
    main()

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

def stgsn(N, maked_num, now_num):
    if now_num != '':
        if int(now_num) > N:
            return

        maked_num.append(now_num)

    stgsn(N, maked_num, now_num + '7')

    stgsn(N, maked_num, now_num + '5')

    stgsn(N, maked_num, now_num + '3')

    return maked_num


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


    maked_num = []
    now_num = ''

    maked_num = stgsn(N, maked_num, now_num)

    ans = [s for s in maked_num if '3' in s and '5' in s and '7' in s]
    print(len(ans))


main()

Solution (Python):
import itertools

n = int(input())

li = [3,5,7]
ans = 0
for i in range(1,11):
    for elm in itertools.product(li,repeat=i):
        if not(7 in elm) or not(5 in elm) or not(3 in elm):
            continue
        ttl = 0
        for j in range(len(elm)):
            ttl += elm[j]*(10**j)
        if ttl<=n:
            
            ans += 1  

print(ans)