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

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)


dp = list3d(N+1, 1<<3, 2, 0)
dp[0][0][0] = 1
for i in range(N):
    a = int(S[i])
    for bit in range(1<<3):
        
        if bit == 0:
            dp[i+1][bit][1] += dp[i][bit][0]
            dp[i+1][bit][1] += dp[i][bit][1]
        
        for k, x in enumerate([3, 5, 7]):
            dp[i+1][bit|1<<k][1] += dp[i][bit][1]
            if a == x:
                dp[i+1][bit|1<<k][0] += dp[i][bit][0]
            elif a > x:
                dp[i+1][bit|1<<k][1] += dp[i][bit][0]

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

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):
from itertools import product
N = int(input())
n = 3
ans = 0
while True:
    for s in product('357', repeat=n):
        s = ''.join(s)
        if N < int(s):
            break
        if '3' in s and '5' in s and '7' in s:
            ans += 1
    else:
        n += 1
        continue
    break
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 itertools

N = input()
count = 0
list = ["3", "5", "7"]

for i in range(3, len(N)):
    
    count += 3**i - (2**i) * 3 + 3

for i in itertools.product(list, repeat=len(N)):
    if int("".join(i)) <= int(N):
        if "3" in i and "5" in i and "7" in i:
            
            count += 1
print(count)

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


def dfs(depth, s):
    if depth == 9:
        n = int(s)
        if '0' not in str(n) \
            and '3' in str(n) \
            and '5' in str(n) \
            and '7' in str(n):
            N753.add(n)
        return

    dfs(depth+1, s+'0')
    dfs(depth+1, s+'3')
    dfs(depth+1, s+'5')
    dfs(depth+1, s+'7')

dfs(0, '')

ans = len([n for n in N753 if n <= N])
print(ans)

Solution (Python):
import sys
from collections import deque

N=int(input())
M=3**9+1
S="357"
vX=[]
appX=vX.append

vQ = deque(S)
tp = vQ.popleft
pb = vQ.append

while vQ:
  p = tp()
  if len(p)<9:
    for n in S:
      c = p + n
      pb(c)
      if all(s in c for s in S):
        appX(int(c))
print(vX[:20], file=sys.stderr)

print(sum(x<=N for x in vX))

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

Solution (Python):
import itertools
s = int(input())
N = len(str(s))
def A(n):
    return (3 ** n) - (3 * 2 ** n) + 3
ans = 0
if s < 357:
    print(0)
elif N > 3:
    for i in range(N-1,2,-1):
        ans += A(i)
    seq = ("3","5","7")
    S = list(itertools.product(seq,repeat=N))
    for j in S:
        j = list(j)
        if "3" in j and "5" in j and "7" in j:
            j = "".join(j)
            if int(j) <= s:
                ans += 1
    print(ans)
elif N == 3:
    seq = ("3","5","7")
    S = list(itertools.product(seq,repeat=N))
    for j in S:
        j = list(j)
        if "3" in j and "5" in j and "7" in j:
            j = "".join(j)
            if int(j) <= s:
                ans += 1
    print(ans)

Solution (Python):
def sft(n, num, add):
    int_sft = int(num+add)
    if int_sft > n:
        return True
    else:
        l.append(int_sft)
        sft(n, num+add, "3")
        sft(n, num+add, "5")
        sft(n, num+add, "7")

l=[]
n = int(input())
sft(n, "", "3")
sft(n, "", "5")
sft(n, "", "7")
le = []
for i in range(len(l)):
    c3 = str(l[i]).count("3")
    c5 = str(l[i]).count("5")
    c7 = str(l[i]).count("7")
    if c3 > 0 and c5 > 0 and c7 > 0:
        le.append(l[i])
print(len(list(set(le))))

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

ans = 0

for i in range(3,len(str(n))+1):
    for p in product('753',repeat=i):
        if n >= int(''.join(list(p))) and all(list(p).count(c) > 0 for c in '753'): ans += 1

print(ans)

Solution (Python):
import itertools

n=int(input())
c=0
for i in range(len(str(n))+1):
      for j in list(itertools.product((3,5,7),repeat=i)):
            if (3 in j) and (5 in j) and (7 in j):
                  if n >=int((''.join(list(map(str,j))))):
                        c+=1
print(c)

Solution (Python):
import itertools
N = input()
ans = 0

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

print(dfs(''))

Solution (Python):

import sys
input = sys.stdin.readline

a = int(input())

nums = [3,5,7]
digit_l = [[3,5,7]]
digit = 2

while digit <= 9:
    
    temp = []
    ta = temp.append
    base = 10**(digit-1)
    for i in nums:
        for j in digit_l[digit-2]:
            ta(j+base*i)
    digit_l.append(temp)
    digit+=1
candidate = []
for i in digit_l:
    candidate += i
candidate_str = list(map(str,candidate))

check_753 = lambda x:1 if "3" in x and "5" in x and "7" in x else 0
candidate_check = list(map(check_753,candidate_str))


from bisect import bisect_right
print(sum(candidate_check[0:bisect_right(candidate,a)]))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

num = ['0', '3', '5', '7']
cand = []
for i1 in num:
	for i2 in num:
		for i3 in num:
			for i4 in num:
				for i5 in num:
					for i6 in num:
						for i7 in num:
							for i8 in num:
								for i9 in num:
									for i10 in num:
										s = i1+i2+i3+i4+i5+i6+i7+i8+i9+i10
										cand.append(int(s))

N = INT()
ans = []
for c in cand:
	if c <= N and	str(c).count('3') >= 1 and str(c).count('5') >= 1 and str(c).count('7') >= 1 and str(c).count('0') < 1:
		ans.append(c)

print(len(ans))

Solution (Python):
def dfs(s,n):
    if int(s)>n:
        return 0
    cur = 0
    if all(s.count(c) > 0 for c in '753'):
        cur = 1
    for c in "753":
        cur += dfs(s+c,n)
    return cur
def examC():
    N = I()
    ans = dfs("0",N)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Solution (Python):
from collections import deque

n = int(input())

qu = deque([7,5,3])
cnt = 0

while qu:
	t = qu.popleft()
	if t > n:
		continue
	if set(str(t)) == {'7','5','3'}:
		cnt += 1
	qu.append(t*10+7)
	qu.append(t*10+5)
	qu.append(t*10+3)

print(cnt)

Solution (Python):
from itertools import product as pr
n=int(input())
if n<357:
  print(0)
  exit()

l=[]
for i in range(3,len(str(n))+1):
  l+=list(pr('753',repeat=i))

ans=0

for x in l:
  if int(''.join(x))>n:
    continue
  if x.count('3')>0 and x.count('5')>0 and x.count('7')>0:
    ans+=1
print(ans)

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

def fes(cul=0):
    if cul > N:
        return 0 
    counter = 0

    if "3" in str(cul) and "5" in str(cul) and "7" in str(cul):
        counter += 1
    counter += fes(cul * 10 + 3)
    counter += fes(cul * 10 + 5)
    counter += fes(cul * 10 + 7)

    return counter

print(fes())

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

def fes(cul='0'):
    if int(cul) > N:
        return 0 
    counter = 0
    if "3" in cul and "5" in cul and "7" in cul:
        counter += 1
    counter += fes(cul + "3")
    counter += fes(cul + "5")
    counter += fes(cul + "7")

    return counter

print(fes())

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

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

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

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

for i in range(3,len(str(n))+1):
    for ptn in itertools.product((3,5,7),repeat=i):
        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
            continue
        a=int("".join(list(map(str,ptn))))
        if a<=n:
            ans+=1
print(ans)

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

for i in range(3, len(str(N))+1):
    for ptn in itertools.product((3,5,7), repeat=i):
        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
            continue
        a = int("".join(list(map(str, ptn))))
        if a <= N:
            ans += 1
print(ans)

Solution (Python):
def main():
    n=int(input())
    keta=len(str(n))
    ary=[]
    cnt=0
    ary.append(0)
    ary.append([3,5,7])
    
    if keta<=2:
        print(0)
        return
    for i in range(2,keta+1):
        temp=[]
        for j in range(0,3**(i-1)):
            temp3=ary[i-1][j]*10+3
            temp5=ary[i-1][j]*10+5
            temp7=ary[i-1][j]*10+7
            if '3' in str(temp3) and '5' in str(temp3) and '7' in str(temp3) and temp3 <= n :
                cnt+=1
            if '3' in str(temp5) and '5' in str(temp5) and '7' in str(temp5) and temp5 <= n:
                cnt+=1
            if '3' in str(temp7) and '5' in str(temp7) and '7' in str(temp7) and temp7 <= n:
                cnt+=1
            temp.append(temp3)
            temp.append(temp5)
            temp.append(temp7)
        ary.append(temp)
    print(cnt)
    
    
if __name__=='__main__':
    main()

Solution (Python):

x=[0,7,5,3]
a=[]
k=0

def new_num(c):
    global x
    d=0
    for i in range(9):
        d+=(10**i)*x[c[i]]
    return d

for i0 in range(4):
    for i1 in range(4):
        for i2 in range(4):
            for i3 in range(4):
                for i4 in range(4):
                    for i5 in range(4):
                        for i6 in range(4):
                            for i7 in range(4):
                                for i8 in range(4):
                                    l1=new_num([i0,i1,i2,i3,i4,i5,i6,i7,i8])
                                    l2=str(l1)
                                    if ("3" in l2) and ("5" in l2) and ("7" in l2) and ("0" not in l2):
                                        a.append(l1)
a.sort()
co=0
n=int(input())
for i in a:
    if i<=n:
        
        co+=1
    else:
        break
print(co)

Solution (Python):
N = input()
n = len(N)
N = int(N)
s = ["1","7","5","3"]
ans = 0
for i in range(4**n):
    st = "0"
    while i != 0:
        st = st + s[i%4]
        i = i//4
    if "1" in st:
        b = False
    else:
        b = True
    for j in s[1:]:
        if not j in st:
            b = False
    if b and int(st) <= N:
        ans += 1
print(ans)

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

ans=0
def make753(s,n):
  global ans
  if s<=N:
    if "3" in str(s) and "5" in str(s) and "7" in str(s):
      ans+=1
  if n>0:
    for i in 7,5,3:
      make753(10*s+i,n-1)
      
make753(0,len(str(N)))
print(ans)

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

def f(s):
    if int(s) > N:
        return 0
    
    ret = 1 if all([c in s for c in '753']) else 0
    for c in '753':
        ret += f(s + c)
    
    return ret

print(f('0'))

Solution (Python):
from itertools import product
n = input()
p = []
for i in range(len(n)):
	p += list(product(["7","5","3"], repeat = i+1))
a = []
for i in p:
	if ("7" not in i) or ("5" not in i) or ("3" not in i):
		continue
	else:
		if int("".join(i)) <= int(n):
			a.append(int("".join(i)))
print (len(a))

Solution (Python):
n = int(input())
taegrt = ["3","5","7"]
ans = 0
count_num = []

def dfs(s):
    global count_num
    global taegrt
    global ans 
    for val in taegrt:
        tmp = s+val
        if int(tmp) > n:
            return
        if tmp in count_num:
            continue
        count_num.append(tmp)
        
        if "7" in list(tmp) and "5" in list(tmp) and "3" in list(tmp):
            ans += 1
        dfs(tmp)

for i in taegrt:
    dfs(i)

print(ans)

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time

input = sys.stdin.readline


sys.setrecursionlimit(2147483647)


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


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


def main():
    N = int(input())
    number = str(N)
    L = len(number)
    dp = [[[[[0 for t in range(2)]
                for f in range(2)]
                for s in range(2)]
                for smaller in range(2)]
                for j in range(L + 1)]

    n = []
    for i in range(L):
        n.append(int(number[i]))

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

    for k in range(L):
        for smaller in range(2):
            for s in range(2):
                for f in range(2):
                    for t in range(2):
                        li = [0, 7, 5, 3] if smaller else [q for q in [0, 7, 5, 3] if q <= n[k]]
                        for m in li:
                            if k + 2 == L:
                                if s == 1 and f == 0 and t == 0 and m != 7:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 0 and f == 1 and t == 0 and m != 5:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 0 and f == 0 and t == 1 and m != 3:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                
                            elif k + 1 == L:
                                if s == 0 and f == 1 and t == 1 and m == 7:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 1 and f == 0 and t == 1 and m == 5:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 1 and f == 1 and t == 0 and m == 3:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                
                            else:
                                if s == 0 and f == 0 and t == 0 and m == 0:
                                    dp[k+1][1][0][0][0] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        

    
    
    print(dp[L][0][1][1][1] + dp[L][1][1][1][1])


def sub():
    N = int(input())
    number = str(N)
    length = len(number)
    ans = 0

    stack = ['']
    while len(stack) > 0:
        s = stack.pop()

        if len(s) >= length:
            remain = set([s[i] for i in range(len(s))]) - set('0')
            if len(remain) == 3 and int(s) <= N:
                ans += 1
                
            continue

        for i in ['0', '7', '5', '3']:
            if (i == '0' and len(s) == 0) or (len(s) > 0 and s[-1] == '0'):
                stack.append(s + i)
            elif i != '0':
                stack.append(s + i)

    print(ans)


if __name__ == '__main__':
    sub()

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time

input = sys.stdin.readline


sys.setrecursionlimit(2147483647)


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


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


def main():
    N = int(input())
    number = str(N)
    L = len(number)
    dp = [[[[[0 for t in range(2)]
                for f in range(2)]
                for s in range(2)]
                for smaller in range(2)]
                for j in range(L + 1)]

    n = []
    for i in range(L):
        n.append(int(number[i]))

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

    for k in range(L):
        for smaller in range(2):
            for s in range(2):
                for f in range(2):
                    for t in range(2):
                        li = [0, 7, 5, 3] if smaller else [q for q in [0, 7, 5, 3] if q <= n[k]]
                        for m in li:
                            if k + 2 == L:
                                if s == 1 and f == 0 and t == 0 and m != 7:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 0 and f == 1 and t == 0 and m != 5:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 0 and f == 0 and t == 1 and m != 3:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                
                            elif k + 1 == L:
                                if s == 0 and f == 1 and t == 1 and m == 7:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 1 and f == 0 and t == 1 and m == 5:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 1 and f == 1 and t == 0 and m == 3:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                
                            else:
                                if s == 0 and f == 0 and t == 0 and m == 0:
                                    dp[k+1][1][0][0][0] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        

    
    
    print(dp[L][0][1][1][1] + dp[L][1][1][1][1])


if __name__ == '__main__':
    main()

Solution (Python):
import itertools as it

N = input()
list_753 = []
for i in range(3, len(N) + 1):
    for i_753 in it.product("357", repeat=i):
        if "3" in i_753 and "5" in i_753 and "7" in i_753:
            list_753.append(int("".join(i_753)))

ans = 0
for i in list_753:
    if i <= int(N):
        ans += 1
    else:
        break
print(ans)

Solution (Python):
n = int(input())
def sitigo(num):
    if int(num) > n:
        return 0
    count3 = False
    count5 = False
    count7 = False
    s = 0

    for i in range(len(str(num))):
        if str(num)[i] == "3":
            count3 = True
        if str(num)[i] == "5":
            count5 = True
        if str(num)[i] == "7":
            count7 = True
        if count3 and count5 and count7:
            s = 1

    return sitigo(int(str(num)+"3")) + sitigo(int(str(num)+"5")) + sitigo(int(str(num)+"7")) + s
print(sitigo(0))

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

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

print(dfs("0"))

Solution (Python):
from itertools import product

N=int(input())

k=len(str(N))

l=[3,5,7]

P_list=[]

for j in range(3,k+1):
    for i in product(l,repeat=j):
        temp=list(map(str,i))
        P_list.append("".join(temp))

cnt=0

for i in P_list:
    if ("3" in i) and ("5" in i) and ("7" in i):
        if int(i)<=N:
            cnt+=1
print(cnt)

Solution (Python):

import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
keta=len(str(n))
for i in range(3,keta):
    ans+=3**i-2**i*3+3
    
ite=list(itertools.product((3,5,7),repeat=keta))
ite.sort()
for ii in ite:
    bi=list(map(str,ii))
    ai = int(''.join(bi))
    if n>=ai:
        if (3 in ii) and (5 in ii) and  (7 in ii):
            ans+=1
    else:
        break

print(ans)

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

numlist = []
keta = len(str(N-1))
for k in range(3,keta+1):
    for i in range(3**k):
        cur = ''
        tmp = i
        tk = 0
        while tk<k:
            cur += str(tmp%3)
            tmp //= 3
            tk += 1

        numlist.append(cur)

ans = 0
coeff = [3,5,7]
for s in numlist:
    if len(s)<3 :continue
    flag = [False,False,False]
    val = 0
    base = 1
    for t in s:
        flag[int(t)] = True
        val += coeff[int(t)] * base
        base *= 10
    if (sum(flag)==3) and (val <= N):
        ans += 1
print(ans)

Solution (Python):
from itertools import product
N = int(input())
d = len(str(N))
ans = []
for i in range(3, d+1):
    cs = product([3,5,7], repeat=i)
    for c in cs:
        if set(c) == {3, 5, 7}:
            if i < d or (i == d and int(''.join(map(str, c))) <= N):
                ans.append(c)
print(len(ans))

Solution (Python):
import itertools

N = int(input())
M=len(str(N))
count=0
for i in range(3,M):
  for x in itertools.product('357',repeat=i):
    if '3' in x and '5' in x and '7' in x:
      count +=1
for x in itertools.product('357',repeat=M):
  if '3' in x and '5' in x and '7' in x:
    x_i =0
    for j in range(len(x)):
      x_i +=int(x[j])*10**(len(x)-j-1)
    if x_i<=N:
      count +=1
print(count)

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

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

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

def make_753(num):
    global count
    b = str(num) + '3'
    c = str(num) + '5'
    d = str(num) + '7'
    if int(b) > n:
        return
    elif '3' in str(b) and '5' in str(b) and '7' in str(b):
        count += 1
        make_753(b)
    else:
        make_753(b)
    if int(c) > n:
        return
    elif '3' in str(c) and '5' in str(c) and '7' in str(c):
        count += 1
        make_753(c)
    else:
        make_753(c)
    if int(d) > n:
        return
    elif '3' in str(d) and '5' in str(d) and '7' in str(d):
        count += 1
        make_753(d)
    else:
        make_753(d)


make_753('')

print(count)

Solution (Python):
N = input()


def dfs(s=""):
    if s != "":
        if int(s) > int(N):
            return 0
    if (len(s) == s.count("7") + s.count("5") + s.count("3")) and (s.count("7") >= 1 and s.count("5") >= 1 and s.count("3") >= 1):
        ret = 1
    else:
        ret = 0
    for l in ["3", "5", "7"]:
        ret += dfs(s+l)

    return ret


print(dfs(""))

Solution (Python):
n=int(input())
length = len(str(n))+1
se = set()
def moji(s):
    if len(s)>=length:
        return
    se.add(s)
    moji(s+'5')
    moji(s+'7')
    moji(s+'3')
moji('')
li=list(sorted(se))
ans = 0
for i in li:
    if i == '':
        continue
    if '3' not in i or '5' not in i or '7' not in i:
        continue
    if int(i)<=n:
        ans+=1
print(ans)

Solution (Python):
import sys
from itertools import combinations
input = sys.stdin.readline

N = int(input())
leng = len(str(N))
if leng <= 2:
    print(0)
    exit()

def f(N, l, stri):
    if l == 0:
        if int(stri) <= N and '7' in stri and '5' in stri and '3' in stri:
            return 1
        else:
            return 0
    ans = 0
    for i in ['7', '5', '3']:
        ans += f(N, l-1, stri + i)
    return ans

ans = 0
for l in range(3, leng+1):
    ans += f(N, l, '')

print(ans)

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

nums=[]
all=set(['3','5','7'])
def dfs(x):
  if x>N:
    return
  if x>=357:
    if len(all-set(list(str(x))))==0:
      nums.append(x)
  for i in (3,5,7):
    dfs(x*10+i)

dfs(0)
print(len(nums))

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

list753 = ["3","5","7"]

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

Solution (Python):
N = int(input())
ans = 0
from itertools import product
for i in range(3,10):
  for p in product(['3','5','7'], repeat=i):
    s = ''.join(p)
    if '3' in s and '5' in s and '7' in s and int(s)<=N:
      ans += 1
print(ans)

Solution (Python):
import itertools

N = int(input())
N_str = str(N)

ans=0
num = ["0","3","5","7"]
for s in itertools.product(num,num,num,num,num,num,num,num,num):
    n = int("".join(s))
    c3 = str(s).count("3")
    c5 = str(s).count("5")
    c7 = str(s).count("7")
    
    if n <= N and c3>=1 and c5>=1 and c7>=1 and c3+c5+c7==len(str(n)):
        ans+=1
        
    elif n>N:
        break
print(ans)

Solution (Python):

N = int(input())
def sft(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 += sft(s+c)
    return cnt
    
print(sft('0'))

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

def dfs(s):
    if int(s) > n:
        return 0
    cnt = [0, 1]['7' in s and '5' in s and '3' in s]
    for x in '753':
        cnt += dfs(s + x)
    return cnt

print(dfs('0'))

Solution (Python):
import sys
sys.setrecursionlimit(100000)
n=int(input())
m=len(str(n))
L=[]
def dfs(i,num):
    if i==m+1:
        return
    if 0<i<m+1:
        if len(set(num))==3 and int(num)<=n:
            L.append(int(num))
    dfs(i+1,num+'3')
    dfs(i+1,num+'5')
    dfs(i+1,num+'7')
dfs(0,'')
print(len(L))

Solution (Python):
N = int(input())
n = ["3", "5", "7"]
l = 0
r = 3
x = 1
flag = True
while flag:
    for m in (3, 5, 7):
        if not flag:
            break
        for i in range(l, r):
            y = int(n[i])+m*10**x
            if y > N:
                flag = False
                break
            n.append(str(y))

    l = r
    r = len(n)   
    x += 1

res = 0
for s in n:
    if "3" in s and "5" in s and "7" in s:
        res += 1

print(res)

Solution (Python):
n=input()
p=""
for i in range(len(n)):
	if int(n[i])>7:
		p+="3"*(len(n)-i)
		break
	elif int(n[i])==7:
		p+="3"
	elif int(n[i])==6:
		p+="2"
		p+="3"*(len(n)-i-1)
		break
	elif int(n[i])==5:
		p+="2"
	elif int(n[i])==4:
		p+="1"
		p+="3"*(len(n)-i-1)
		break
	elif int(n[i])==3:
		p+="1"
	else:
		p+="0"
total=0
for i in range(len(n)):
	total+=int(p[-i-1])*(4**i)
def tet(x):
	q=""
	while x!=0:
		q+=str(x%4)
		x//=4
	if len(q)==0:
		q="0"
	return q[::-1]
ans=[]
cnt=0
for i in range(total):
	if tet(i+1).count("0")==0:
		ans.append(tet(i+1))
for i in range(len(ans)):
	if ans[i].count("1") and ans[i].count("2")\
	and ans[i].count("3"):
		cnt+=1
print(cnt)

Solution (Python):
num = (3, 5, 7)
list_357 = ["3", "5", "7"]
list_357_tmp = []
list_753 = []
for i in range(8):
    for j in num:
        for k in list_357:
            list_357_tmp.append(str(j) + k)
    list_357.extend(list_357_tmp)
    list_357_tmp.clear()
for i in list_357:
    if "3" in i and "5" in i and "7" in i:
        list_753.append(int(i))
list_753=set(sorted(list_753))
list_753=sorted(list_753)
N = int(input())
ans = 0
for i in range(len(list_753)):
    if N < list_753[i]:
        ans = i
        break
    elif i == len(list_753)-1:
        ans = i+1
print(ans)