Problem:
 Score : 300 points    Problem Statement You are given an integer N . Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?  Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:   When the number is written in base ten, each of the digits 7 , 5 and 3 appears at least once, and the other digits never appear.       Constraints  1 \leq N < 10^9  N is an integer.         Input Input is given from Standard Input in the following format:  N       Output Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).        Sample Input 1 575      Sample Output 1 4  There are four Shichi-Go-San numbers not greater than 575 : 357, 375, 537 and 573 .       Sample Input 2 3600      Sample Output 2 13  There are 13 Shichi-Go-San numbers not greater than 3600 : the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577 .       Sample Input 3 999999999      Sample Output 3 26484

Solution (Python):
N = int(input())
def n_ary(l,d): 
    if d == 1:
        return(l)
    n = len(l)
    ll = n_ary(l,d-1)
    lll = []
    for i in l:
        for j in ll[n*(n**(d-2)-1)//(n-1):]:
            lll.append(i+j)
    return(ll+lll)
possible = [i.replace('0','3').replace('1', '5').replace('2','7') for i in n_ary(['0','1','2'],9)] 
print(len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= N)]))

Solution (Python):
N = int(input())
def n_ary(l,d): 
    if d == 1:
        return(l)
    n = len(l)
    ll = n_ary(l,d-1)
    lll = []
    for i in l:
        for j in ll[n*(n**(d-2)-1)//(n-1):]:
            lll.append(i+j)
    return(ll+lll)
possible = [i.replace('0','3').replace('1', '5').replace('2','7') for i in n_ary(['0','1','2'],9)] 
print(len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= 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 '357':
        ret += dfs(s + c)
    return ret


print(dfs('0'))

Solution (Python):
N = input()

def search(i):
        if int(i) > int(N):
                return 0

        nums = [3, 5, 7]
        count = 0
        if all(i.count(str(n)) > 0 for n in nums):
                count = 1
        else:
                count = 0
        
        for n in nums:
                count += search(i + str(n))
        
        return count

print(search(str(0)))

Solution (Python):
def make(num):
  if num==1 or num==2:
    return []
  l3=['357','375','537','573','735','753']
  if num==3:
    return l3
  l4=set()
  for i in range(len(l3)):
    l4.add('3'+l3[i])
    l4.add('5'+l3[i])
    l4.add('7'+l3[i])
    for j in range(1,3):
      l4.add(l3[i][:j]+'3'+l3[i][j:])
      l4.add(l3[i][:j]+'5'+l3[i][j:])
      l4.add(l3[i][:j]+'7'+l3[i][j:])
    l4.add(l3[i]+'3')
    l4.add(l3[i]+'5')
    l4.add(l3[i]+'7')
  l4=list(l4)
  if num==4:
    return l4+l3
  l5=set()
  for i in range(len(l4)):
    l5.add('3'+l4[i])
    l5.add('5'+l4[i])
    l5.add('7'+l4[i])
    for j in range(1,4):
      l5.add(l4[i][:j]+'3'+l4[i][j:])
      l5.add(l4[i][:j]+'5'+l4[i][j:])
      l5.add(l4[i][:j]+'7'+l4[i][j:])
    l5.add(l4[i]+'3')
    l5.add(l4[i]+'5')
    l5.add(l4[i]+'7')
  l5=list(l5)
  if num==5:
    return l5+l4+l3
  l6=set()
  for i in range(len(l5)):
    l6.add('3'+l5[i])
    l6.add('5'+l5[i])
    l6.add('7'+l5[i])
    for j in range(1,5):
      l6.add(l5[i][:j]+'3'+l5[i][j:])
      l6.add(l5[i][:j]+'5'+l5[i][j:])
      l6.add(l5[i][:j]+'7'+l5[i][j:])
    l6.add(l5[i]+'3')
    l6.add(l5[i]+'5')
    l6.add(l5[i]+'7')
  l6=list(l6)
  if num==6:
    return l6+l5+l4+l3
  l7=set()
  for i in range(len(l6)):
    l7.add('3'+l6[i])
    l7.add('5'+l6[i])
    l7.add('7'+l6[i])
    for j in range(1,6):
      l7.add(l6[i][:j]+'3'+l6[i][j:])
      l7.add(l6[i][:j]+'5'+l6[i][j:])
      l7.add(l6[i][:j]+'7'+l6[i][j:])
    l7.add(l6[i]+'3')
    l7.add(l6[i]+'5')
    l7.add(l6[i]+'7')
  l7=list(l7)
  if num==7:
    return l7+l6+l5+l4+l3
  l8=set()
  for i in range(len(l7)):
    l8.add('3'+l7[i])
    l8.add('5'+l7[i])
    l8.add('7'+l7[i])
    for j in range(1,7):
      l8.add(l7[i][:j]+'3'+l7[i][j:])
      l8.add(l7[i][:j]+'5'+l7[i][j:])
      l8.add(l7[i][:j]+'7'+l7[i][j:])
    l8.add(l7[i]+'3')
    l8.add(l7[i]+'5')
    l8.add(l7[i]+'7')
  l8=list(l8)
  if num==8:
    return l8+l7+l6+l5+l4+l3
  l9=set()
  for i in range(len(l8)):
    l9.add('3'+l8[i])
    l9.add('5'+l8[i])
    l9.add('7'+l8[i])
    for j in range(1,8):
      l9.add(l8[i][:j]+'3'+l8[i][j:])
      l9.add(l8[i][:j]+'5'+l8[i][j:])
      l9.add(l8[i][:j]+'7'+l8[i][j:])
    l9.add(l8[i]+'3')
    l9.add(l8[i]+'5')
    l9.add(l8[i]+'7')
  l9=list(l9)
  if num==9 or num==19:
    return l9+l8+l7+l6+l5+l4+l3

n=int(input())
l=len(str(n))
arr=make(l)
if len(arr)==0:
  print(0)
else:
  cnt=0
  for i in range(len(arr)):
    if int(arr[i])<=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 c in '753':
        ret += dfs(s + c)

    return ret


print(dfs('0'))

Solution (Python):
from collections import deque
def dfs(N):
    stack=deque(["3","5","7"])
    cnt=0
    while stack:
        cand=stack.pop()
        if all(cand.count(c)>0 for c in "357"):
            cnt+=1
        for c in "357":
            if int(cand+c)<=N:
                stack.append(cand+c)
    return cnt
if __name__=="__main__":
    N=int(input())
    print(dfs(N))

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 i in '753':
        ans += dfs(s+i)
    return ans

print(dfs('0'))

Solution (Python):
from math import factorial
from sys import exit, stdin
N = int(stdin.readline().rstrip())
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())

a = [3, 5, 7]

for i in range(1, 9):
    added_a = []
    for _a in a:
        added_a.append(3*(10**i)+_a)
        added_a.append(5*(10**i)+_a)
        added_a.append(7*(10**i)+_a)
    a.extend(added_a)

b = []
for _a in a:
    if _a <= N:
        b.append(_a)

c = []
for _b in b:
    _s = str(_b)
    if "3" in _s and "5" in _s and "7" in _s and "0" not in _s:
        c.append(_b)

print(len(c))

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_str = input()
n = int(n_str)
digit = len(n_str)
top = int(n_str[0])

def calc_add(digit):
    return (3 ** (digit) - ((2 ** (digit)) * 2) + 1) if digit >= 2 else 0 

answer = 0
if(digit > 3):
    for(pre_digit) in range(3, digit):
        answer += calc_add(pre_digit - 1) * 3

add = calc_add(digit - 1)
if(top > 3):
    
    answer += add
if(top > 5):
    
    answer += add
if(top > 7):
    
    answer += add

if (top == 3 or top == 5 or top == 7):
    
    
    chk_list = []
    char_list = ["3", "5", "7"]
    counter = 0
    while True:
        string = str(top)
        cp_counter = counter
        for index in reversed(range(0, (digit - 1))):
            string += char_list[(cp_counter // (3 ** (index)))]
            cp_counter -=  (3 ** (index)) * (cp_counter // (3 ** (index)))
        if int(string) <= n:
           chk_list.append(tuple(string))
        counter += 1
        if counter >= 3 ** (digit - 1):
            break
    
    for string_number in chk_list:
        count3 = 0
        count5 = 0
        count7 = 0
        for num in string_number:
            if(int(num) == 3):
                count3 += 1
            elif(int(num) == 5):
                count5 += 1
            elif(int(num) == 7):
                count7 += 1 
            else:
                break
        else:
            if(count3 != 0 and count5 != 0 and count7 != 0):
                answer += 1
print (answer)

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


def dfs(k, a, b, c):
    global num
    if min(a, b, c) > 0 and int(k) <= int(N):
        num += 1
    elif int(k) > int(N):
        return

    dfs(k + '3', 1, b, c)
    dfs(k + '5', a, 1, c)
    dfs(k + '7', a, b, 1)


dfs('3', 1, 0, 0)
dfs('5', 0, 1, 0)
dfs('7', 0, 0, 1)
print(num)

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

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

print(f('0'))

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

def dfs(s, n):
    if  int(s) > n:
        return 0
    ret = 0
    if all([c in s for c in '753']):
        ret = 1
    for c in '753':
        ret += dfs(s + c, n)
    return ret 

print(dfs('0', n))

Solution (Python):
S = input()
N = len(S)
K = int(S)
num = 0


def dfs(k, a, b, c):
    global num
    if min(a, b, c) > 0 and int(k) <= K:
        num += 1
    if int(k) > K:
        return

    dfs(k + '3', 1, b, c)
    dfs(k + '5', a, 1, c)
    dfs(k + '7', a, b, 1)


dfs('3', 1, 0, 0)
dfs('5', 0, 1, 0)
dfs('7', 0, 0, 1)
print(num)

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



def check(num):

    if num > N:
        return 0

    
    str_num =  str(num)

    count = 0

    if "7" in str_num and "5" in str_num and "3" in str_num:
        count += 1

    count += check(num*10 + 7)
    count += check(num*10 + 5)
    count += check(num*10 + 3)
    return count

    
ret = 0
ret += check(7)
ret += check(5)
ret += check(3)
print(ret)

Solution (Python):
N = int(input())
stack = [(0, 0)]
ans = 0
while stack:
  s = stack.pop()
  if s[0] > N:
    continue
  if s[1] == 7:
    ans += 1
  stack.append((s[0] * 10 + 3, s[1] | 1))
  stack.append((s[0] * 10 + 5, s[1] | 2))
  stack.append((s[0] * 10 + 7, s[1] | 4))
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):
N = int(input())

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

print(dfs('0'))

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


def dfs(acc):
    if int(acc) > N:
        return 0
    is_hichigosan_num = False
    if '7' in acc and '5' in acc and '3' in acc:
        is_hichigosan_num = True

    return sum([
        1 if is_hichigosan_num else 0,
        dfs(acc + '7'),
        dfs(acc + '5'),
        dfs(acc + '3')
    ])


print(dfs('0'))

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


def dfs(acc, sevens, fives, threes):
    if int(acc) > N:
        return 0
    is_hichigosan_num = False
    if sevens >= 1 and fives >= 1 and threes >= 1:
        is_hichigosan_num = True

    return sum([
        1 if is_hichigosan_num else 0,
        dfs(acc + '7', sevens+1, fives, threes),
        dfs(acc + '5', sevens, fives+1, threes),
        dfs(acc + '3', sevens, fives, threes+1)
    ])


print(dfs('0', 0, 0, 0))

Solution (Python):
import itertools

if __name__ == '__main__':
    N = int(input())

    answer = 0

    for i_repeat in range(1, len(str(N))+1):
        for i in itertools.product([7, 5, 3], repeat=i_repeat):
            i_list = list(i)
            str_i_list = str(i_list)
            cnt_7 = str_i_list.count('7')
            cnt_5 = str_i_list.count('5')
            cnt_3 = str_i_list.count('3')
            if cnt_7 >= 1 and cnt_5 >= 1 and cnt_3 >= 1:
                num = 0
                for j, e in enumerate(i_list):
                    num += int(e) * pow(10, len(i_list)-j-1)
                if num <= N:
                    answer += 1
    print(answer)

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

cnt = 0
def dfs(n):
    global cnt
    if len(n) >= 11:
        return 0
    for s in '357':
        dfs(n+s)
    if int(n) <= N and '3' in n and '5' in n and '7' in n:
        cnt += 1
    return cnt

print(dfs('0'))

Solution (Python):
n = int(input())
L = [3, 5, 7]

cnt = 0


def f(s):
    if s > n:
        return False

    str_s = str(s)
    return sum(f(s*10 + i) for i in L) + ("7" in str_s and "5" in str_s and "3" in str_s)


print(f(0))

Solution (Python):
from collections import deque
N = int(input())
stack = deque(["0"])
cnt = 0
while len(stack)>0:
    c = stack.pop()
    for s in "357":
        cs = c + s
        
        if int(cs)<=N:
            stack.append(cs)
            if cs.count("3")*cs.count("5")*cs.count("7")>0:
                cnt += 1
print(cnt)

Solution (Python):
from collections import deque
N = int(input())
stack = deque(["0"])
cnt = 0
while len(stack)>0:
    c = stack.pop()
    for s in "753":
        cs = c + s
        
        if int(cs)<=N:
            stack.append(cs)
            if cs.count("3")*cs.count("5")*cs.count("7")>0:
                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 c in '753':
        ret += dfs(s+c) 
    return ret

print(dfs('0'))

Solution (Python):
N = int(input())
cnt = 0
def dfs(n, cnt):
    if int(n) > N:
        return cnt
    if n.count("3") >= 1 and n.count("5") >= 1 and n.count("7") >= 1:
        cnt += 1

    for i in ("3","5","7"):
        cnt = max(cnt, dfs(n+i, cnt))
    return cnt

print(dfs("0", 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())
ans = 0
def chr(i,a):
    global ans
    if i <= 9:
        chr(i+1,a+"7")
        chr(i+1,a+"5")
        chr(i+1,a+"3")
    if i >= 3:
        if a.count("7"):
            if a.count("5"):
                if a.count("3"):
                    if int(a) <= N:    
                        ans += 1
chr(0,"")
print(ans)

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

def dfs(s):
    if int(s) > n:
        return 0
    sum = all(s.count(c) > 0 for c in '753')
    for c in '753':
        sum += dfs(s + c)
    return sum
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):
S = input()

'''
357 375 537 573 735 753 
3357 3375 3537 3573 3735 3753 
5357 5375 5537 5573 5735 5753 
3357,3375,3537,

3けた　、4けた 5 ,6, 7, 8
6,18,54,162,486, 8
sum = [2 * 3,2 * 3 * 3,]
'''

N = len(S)
list375 =['3','5','7']
if N <  3:
    print(0)
    exit(0)

for i in range(N + 1):
    if i ==0:
        continue
    else:
        targetList = list375[:]
        for l in targetList:
            
            list375.append(l + '3')
            list375.append(l + '5')
            list375.append(l + '7')

result = [i for i in list(set(list375)) if int(i) <= int(S) and (i.count('3') >0 and i.count('5') >0 and i.count('7') >0)]

print(len(result))


'''
def judge753():
    if keta[0] < 3:
        return 0
    if keta[0] < 5:
        if keta[1] < 3:
            return 0
        if keta[1] < 5:
            if keta[2] < 5:
                return 0
            if keta[2] < 7:
                return 1
            return 2
        if keta[1] < 7:
            
        return sum[len(S)-1]
    if keta[0] < 7:
        if keta[1] < 3:
            return sum[len(S)-1] + sum[len(S)-2]
        if keta[1] < 5:
            if keta[2] < 5:
        
        return sum[len(S)-1]
        
print(min(absList))
'''

Solution (Python):
from math import log10
N = int(input())
ndig = int(log10(N))+1
def dfs(n, s):
    if n==0:
        return 1 if int(s)<=N and "7" in s and "5" in s and "3" in s else 0
    return sum([dfs(n-1,i+s) for i in ["7","5","3"]])
ans = 0
for i in range(3,ndig+1):
    ans += dfs(i, "")
print(ans)

Solution (Python):
N = input()

def f(s):
    if int(s) > int(N):
        return 0

    if "3" in s and "5" in s and "7" in s:
        cnt = 1
    else:
        cnt = 0

    for t in "3","5","7":
        cnt += f(s + t)

    return cnt

ans = f("0")
print(ans)

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

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

ans = dfs("0")
print(ans)

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

n = int(input())
s = str(n)

counter = 0

for l in range(3, len(s) + 1):
    for v in itertools.product([3, 5, 7], repeat = l):
        if 3 in v and 5 in v and 7 in v:
            p = [str(p) for p in v]
            p = int("".join(p))
            
            if p <= n:
                counter += 1
                
print(counter)

Solution (Python):
N = input()

def f(s):
    if int(s) > int(N):
        return 0
    for t in '3','5','7':
        if all(['3' in s,'5' in s,'7' in s]):
            ans.append(1)
        f(s+t)

ans=[]
f('0')
print(sum(ans)//3)

Solution (Python):
N = input()

def f(s):
    if int(s) > int(N):
        return 0
    for t in '3','5','7':
        if all(['3' in s,'5' in s,'7' in s]):
            ans.append(1)
        f(s+t)

ans=[]
f('0')
print(sum(ans)//3)

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

def dfs(cur_n, n_3, n_5, n_7, cur_dig) : 
    if cur_dig == n_dig : 
        if cur_n <= N and n_3 >= 1 and n_5 >= 1 and n_7 >= 1 : 

            return 1
        else : 
            return 0

    a = dfs(cur_n*10 +3, n_3 +1, n_5, n_7, cur_dig +1)
    b = dfs(cur_n*10 +5, n_3, n_5 +1, n_7, cur_dig +1)
    c = dfs(cur_n*10 +7, n_3, n_5, n_7 +1, cur_dig +1)
    d = 0
    
    if (n_dig -3) > cur_dig and n_3 == 0 and n_5 == 0 and n_7 == 0 : 
        d = dfs(cur_n, n_3, n_5, n_7, cur_dig +1)
    
    return(a + b + c + d)

print(dfs(0, 0, 0, 0, 0))

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

def joinnum(N, keta, anscount, aaa):
    if aaa.count('3') > 0 and aaa.count('5') > 0 and aaa.count('7') > 0 and int(aaa) <= N:
        anscount += 1

    if keta == len(str(N)):
        return anscount
    else:
        for i in ['3', '5', '7']:
            anscount = joinnum(N, keta + 1, anscount, i + aaa)

        return anscount

print(joinnum(N, 0, 0, ''))

Solution (Python):
from itertools import product

N = int(input())

S = [int(x) for x in str(N)]
n = len(S)


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

for i, j, k, c3, c5, c7 in product(range(n), [0, 1], [0, 1], [0, 1], [0, 1],
                                   [0, 1]):
    num = [0, 3, 5, 7]
    if not j:
        num = [x for x in num if x <= S[i]]
    if k:
        num = [x for x in num if x != 0]
    for x in num:
        f0 = k or x != 0
        f3 = c3 or x == 3
        f5 = c5 or x == 5
        f7 = c7 or x == 7
        dp[i + 1][j or x < S[i]][f0][f3][f5][f7] += dp[i][j][k][c3][c5][c7]

ans = sum([dp[n][j][1][1][1][1] for j in [0, 1]])
print(ans)

Solution (Python):

import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def dfs(s, N):
    if N < int(s):
        return 0

    ret = 1 if all([c in s for c in '753']) else 0
    for c in '753':
        ret += dfs(s + c, N)
    return ret


def solve(N: int):
    return dfs('0', N)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    result = solve(N)
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
from copy import deepcopy
import math
import itertools

N = int(input())




def int2digit(num):
  return(len(str(num)))


def mk753_digit(digit):
  lst_753_tuple = list(itertools.product([7,5,3], repeat=digit))
  lst_753_str = list(map(lambda x: ''.join(map(str, x)), lst_753_tuple))
  lst_753_contain7 = [s for s in lst_753_str if '7' in s]
  lst_753_contain75 = [s for s in lst_753_contain7 if '5' in s]
  lst_753_contain753 = [s for s in lst_753_contain75 if '3' in s]
  lst_753 = list(map(int, lst_753_contain753))
  return lst_753


ans = 0
digit = int2digit(N)
for k in range(digit):
  ans += len(mk753_digit(k))
lst_753_samedigit = mk753_digit(digit)
lst_753_samedigit_smaller = [x for x in lst_753_samedigit if x <= N]
ans += len(lst_753_samedigit_smaller)

print(ans)

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



def check(num):
  if num.count("3") > 0 and num.count("5") > 0 and num.count("7") > 0:
    return True
  else:
    return False
  
ans = 0  
nums = deque()
nums.append(0)
for i in range(1,10): 
  next_queue_list = deque()
  for j in nums:
    for k in [3,5,7]:
      new_num = j * 10 + k
      if new_num <= N:
        if check(str(new_num)):
          ans += 1
        next_queue_list.append(new_num)
  
  nums = next_queue_list
  
  
print(ans)

Solution (Python):
from itertools import product

N = int(input())

S = str(N)
n = len(S)

ans = 0
for i in range(3, n + 1):
    for p in product(['3', '5', '7'], repeat=i):
        x = int(''.join(p))
        if x <= N and len(set(p) & {'3', '5', '7'}) == 3:
            ans += 1
print(ans)

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

def dfs(n, f1, f2, f3):
    if n > N:
        return
    if f1 and f2 and f3:
        global ans
        ans += 1

    dfs(n*10+7, True, f2, f3)
    dfs(n*10+5, f1, True, f3)
    dfs(n*10+3, f1, f2, True) 

dfs(0, False, False, False)
print(ans)

Solution (Python):
import sys

input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
gcd = lambda a:functools.reduce(fractions.gcd,a) 
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) 
lcm = lambda a:functools.reduce(lcm_base,a,1) 

init_dp = lambda v,n:[v]*(n)

import math

ceil = lambda a:math.ceil(a) 
floor = lambda a:math.floor(a) 

def dfs(s,N):
    ans = 0
    if s != '' and int(s) > N:return ans
    if all(c in s for c in '753'):ans+=1
    for c in '753':
        ans += dfs(s+c,N)
    return ans
    
def solution():
    N = input_int()
    sys.setrecursionlimit(N+10)
    ans = dfs('',N)
    print(ans)

if __name__ == '__main__':
    solution()

Solution (Python):
n=int(input())
length=len(str(n))
def f(x):
    return 3**x-3*(2**x)+3
answer=0
for i in range(1,length):
    answer=answer+f(i)
def g(i,s):
    if i==length:
        if int(s)<=n and '3' in s and '5' in s and '7' in s:
            return 1
        else:
            return 0
    else:
        return g(i+1,s+'3')+g(i+1,s+'5')+g(i+1,s+'7')
answer=answer+g(0,'')
print(answer)

Solution (Python):
N = int(input())
s=['0','3','5','7']
must = ['3','5','7']
count = 0
for i_9 in range (4):
    for i_8 in range (4):
        for i_7 in range (4):
            for i_6 in range (4):
                for i_5 in range (4):
                    for i_4 in range (4):
                        for i_3 in range (4):
                            for i_2 in range (4):
                                for i_1 in range (4):
                                    num =s[i_9]+s[i_8]+s[i_7]+s[i_6]+s[i_5]+s[i_4]+s[i_3]+s[i_2]+s[i_1]
                                    num = int(''.join(list(map(str,num))))
                                    if (num<=N) & ('0' not in list(str(num))) & ('3' in list(str(num))) & ('5' in list(str(num))) & ('7' in list(str(num))) :
                                        count +=1
                                        
print(count)

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

def dfs(N, a, b, c):
  if int(N) > S:
    return 0
  res = 0 if a == 0 or b == 0 or c == 0 else 1
  for i in "357":
    if i == "3":
      res += dfs(N+i, a+1, b, c)
    if i == "5":
      res += dfs(N+i, a, b+1, c)
    if i == "7":
      res += dfs(N+i, a, b, c+1)
  return res

print(dfs("0", 0, 0, 0))

Solution (Python):
import sys

input = sys.stdin.readline
N = int(input())

num_list = [3, 5, 7]
count = 0
while len(num_list) > 0:
    base = num_list.pop()
    for i in [3, 5, 7]:
        v = base*10+i
        if v <= N:
            num_list.append(v)
            if ('3' in str(v)) and ('5' in str(v)) and ('7' in str(v)):
                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):
N = int(input())
ans = []

def shichigo(n):
    global ans
    if int(n) > N:
        return
    if all([(s in n) for s in "753"]):
        ans.append(n)
    shichigo(str(int(n) * 10 + 3))
    shichigo(str(int(n) * 10 + 5))
    shichigo(str(int(n) * 10 + 7))

if N < 357:
    print(0)
else:
    shichigo('3')
    shichigo('5')
    shichigo('7')
    print(len(set(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 = int(input().strip())
count = 0
for i in range(3, len(str(N))+1):
  for n in itertools.product('753', repeat=i):
    num = int(''.join(n))
    if num > N:
      continue
    if len(set(n)) == 3:
      count += 1
print(count)

Solution (Python):
n = int(input())
def dfs(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 += dfs(s+c)
    return ret

print(dfs('0'))

Solution (Python):
def shichigo(s):
    if '3' not in s:
        return False
    if '5' not in s:
        return False
    if '7' not in s:
        return False
    return True

n = input()

l = [[] for i in range(len(n))]
l[0] = ['3','5','7']
for i in range(1,len(l)):
    for j in range(len(l[i-1])):
        l[i].append('3'+l[i-1][j])
        l[i].append('5'+l[i-1][j])
        l[i].append('7'+l[i-1][j])

ans = 0
for i in range(len(l)):
    for j in range(len(l[i])):
        if int(n) >= int(l[i][j]):
            if shichigo(l[i][j]):
                ans += 1

print(ans)

Solution (Python):
def shichigo(s):
    if '3' not in s:
        return False
    if '5' not in s:
        return False
    if '7' not in s:
        return False
    x = s.replace('3','').replace('5','').replace('7','')
    if x=='':
        return True
    return False

n = input()

l = [[] for i in range(len(n))]
l[0] = ['3','5','7']
for i in range(1,len(l)):
    for j in range(len(l[i-1])):
        l[i].append('3'+l[i-1][j])
        l[i].append('5'+l[i-1][j])
        l[i].append('7'+l[i-1][j])

ans = 0
for i in range(len(l)):
    for j in range(len(l[i])):
        if int(n) >= int(l[i][j]):
            if shichigo(l[i][j]):
                ans += 1

print(ans)

Solution (Python):
def shichigo(s):
    if '3' not in s:
        return False
    if '5' not in s:
        return False
    if '7' not in s:
        return False
    x = s.replace('3','').replace('5','').replace('7','')
    if x=='':
        return True
    return False

n = input()

l = [[] for i in range(len(n))]
l[0] = ['3','5','7']
for i in range(1,len(l)):
    for j in range(len(l[i-1])):
        l[i].append('3'+l[i-1][j])
        l[i].append('5'+l[i-1][j])
        l[i].append('7'+l[i-1][j])

ans = 0
for i in range(len(l)):
    for j in range(len(l[i])):
        if int(n) >= int(l[i][j]):
            if shichigo(l[i][j]):
                ans += 1

print(ans)

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

def dfs(n):
    if n > N:
        return 0
    ret = 0
    count = 0
    for i in ['3', '5', '7']:
        if i in str(n):
            count += 1
    if count == 3:
        ret += 1
    n *= 10
    for i in [3, 5, 7]:
        ret += dfs(n+i)
    return ret

print(dfs(0))

Solution (Python):
from math import log10
from itertools import product

N = int(input())
keta = int(log10(N)) + 1

if keta < 3:
    print(0)
    exit()

count = 0

for k in range(3, keta+1):
    for pair in product([3, 5, 7], repeat=k):
        if len(set(pair)) < 3:
            continue
        tmp = 0
        for i, p in enumerate(pair):
            tmp += p * (10**(k-i-1))
        if N >= tmp:
            count += 1

print(count)

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


def dfs(s):
    if int(s) > N:
        return 0
    f = []
    for n in '753':
        if n in s:
            f.append(True)
        else:
            f.append(False)
    ans = 1 if all(f) else 0
    for n in '753':
        ans += dfs(s + n)
    return ans


print(dfs('0'))

Solution (Python):
import numpy as np

N = int(input())
num = ['3', '5', '7']
numbers_753 = []
prev = ['']
for _ in range(9):
    temp = []
    generated = []
    for p in prev:
        for n in num:
            cand = p+n
            generated.append(cand)
            if '3' in cand and '5' in cand and '7' in cand:
                temp.append(int(p+n))
    numbers_753 += temp
    prev = generated
numbers_753 = np.array(numbers_753)
print(sum(numbers_753 <= N))

Solution (Python):
from itertools import permutations

N = int(input())

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

print(dfs('0'))

Solution (Python):
s = input()
d = len(s)
n = int(s)
cand = []
def produce(text):
  if len(text) == d + 1:
    if '3' in text and '5' in text and '7' in text:
      cand.append(int(text))
    return
  if text[-1] == '0':
    for item in ['0', '3', '5', '7']:
      produce(text + item)
  else:
    for item in ['3', '5', '7']:
      produce(text + item)
produce('0')
print(sum(n >= item for item in cand))

Solution (Python):
ans = 0

def rec(num,flag,co,N):
    global ans
    if num>N:
         return  0

    else:
        if flag  == 0b111:
            
            ans += 1
        return rec(num * 10 + 7, flag|0b001,co + 1,N ) + rec(num * 10 + 3,flag|0b100,co + 1,N ) +rec(num * 10 + 5,flag|0b010 ,co + 1,N )
def c():
    bit07 = 0b001
    bit05 = 0b010
    bit03 = 0b100
    global ans
    N = input()
    N = int(N)
    rec(3,bit03,0,N)
    rec(5,bit05,0,N)
    rec(7,bit07,0,N)

    print(ans)
if __name__ == "__main__":
    c()

Solution (Python):
from itertools import product
n = int(input())
num = ['','3','5','7']
A = set() 
for i in product(num,repeat=9):
    x = "".join(i)
    if len(set(x)) == 3:
        if (int(x) not in A) and (int(x) <= n):
            A.add(int(x))
print(len(A))

Solution (Python):
import numpy as np
N = int(input())
digit = int(np.log10(N))+1

def ok(s):
  if '7' in s and '5' in s and '3' in s and int(s) <= N:
    return True
  return False

def dfs(cur, s):
  if cur == digit:
    return ok(s)
  else:
    ret = ok(s)
    for i in '357':
      ret += dfs(cur+1, s+i)
  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())

def dfs(s):
    if int(s)>n:
       return 0
    b=(all(map(s.count,"357")))
    for c in "357":
        b+=dfs(s+c)
    return b
print(dfs("0"))