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

def func(M_len, M):
  if M_len == 0:
    if len(set(list(M))) == 3:
      N_list.append(M)
  else:
    for i in ['3','5','7']:
      func(M_len-1, M + i)
      
for i in range(len(N)+1):
  func(i, '')
print(len([x for x in N_list if int(x) <= int(N)]))

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

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

print(dfs('0'))

Solution (Python):
N = int(input())
A = []

def f(s):
    if int(s) > N:
        return 0
    if all(s.count(i) >= 1 for i in '753'):
        A.append(int(s))
    for i in '753':
        f(s + i)

f('0')
print(len(A))

Solution (Python):
N = int(input())
A = []

def f(s):
    if s != '' and eval(s) > N:
        return 0
    if all(s.count(i) >= 1 for i in '753'):
        A.append(eval(s))
    for i in '753':
        f(s + i)

f('')
print(len(A))

Solution (Python):
import itertools

N = int(input())

c = 0
n = str(N)
L = len(n)

if L >= 3:
  for j in range(L-2):
    for i in itertools.product(['3', '5', '7'], repeat=j+3):
      if int("".join(i)) <= N and len(set(i)) == 3:
        c += 1

print(c)

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

nums = set([int("".join(n)) for r in range(1,9+1)
              for n in itertools.product(list("753"), repeat=r)])

for chars in ["75","53","37","7","5","3"]:
    nums -= set([int("".join(n)) for r in range(1,9+1)
                   for n in itertools.product(list(chars), repeat=r)])


print(len([n for n in list(nums) if n <= N]))

Solution (Python):
def f(i,ans):
    if int(i) > N:
        return ans
    i = str(i)
    ans += 1 if all([i[1:].count(a) for a in A]) else 0
    for a in A:
        ans += f(i+a,ans)-ans
    return ans
  
N = int(input())
ans = 0
A = '357'
print(f(0,0))

Solution (Python):
import math,sys,itertools

N = int(input())

cnt = 0

base = [3,5,7]

num = set(base)
ans = {}
keta = math.log10(N + 1)
keta = math.ceil(keta) 
tmplist = [0]
for i in range(keta):
    newlist = []
    for j in tmplist:
        for k in base:
            newlist += [j + k * 10 ** i]
        
    num |= set(newlist)
    tmplist = newlist

for x in list(num):
    s = str(x)
    flag = [False,False,False]
    for i in s:
        if i == '3':flag[0] = True
        if i == '5':flag[1] = True
        if i == '7':flag[2] = True
        if flag[0] and flag[1] and flag[2] :
            if x <= N:cnt += 1            
            break
    

print(cnt)

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



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

print(dfs('0'))

Solution (Python):
def dfs(x, bit) :
  if x > N :
    return 0
  res = bit == 7
  res += dfs(10*x + 3, bit|1)
  res += dfs(10*x + 5, bit|2)
  res += dfs(10*x + 7, bit|4)
  return res

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

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

N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    if all([s.count(i) for i in "753"]):
        result = 1
    else:
        result = 0
    
    for i in "753":
        result += dfs(s+i)
    return result

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 math

n = int(input())
first_pos = int(math.log10(n))
count = 0


def find(pos, found=[], permit_9=False, permit_zero=False):
    global n
    global count

    if pos < 0:
        return

    digit = 9 if permit_9 else (n // (10**pos)) % 10

    

    for i in range(0, digit + 1):
        if i == 0 and permit_zero:
            find(pos - 1, found=found, permit_9=permit_9 or i < digit, permit_zero=True)
        if i == 3 or i == 5 or i == 7:
            found.append(i)
            find(pos - 1, found=found, permit_9=permit_9 or i < digit, permit_zero=False)
            if pos == 0 and set(found) == {3, 5, 7}:
                
                count += 1
            found.pop()


find(first_pos, found=[], permit_9=False, permit_zero=True)
print(count)

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):
from itertools import product
N = int(input())

cnt = 0
for i in range(3,10):
    for v in product('357',repeat=i):
        val = ''.join(v)
        if int(val) <= N and '3' in val and '5' in val and '7' in val:
           cnt += 1

print(cnt)

Solution (Python):
n = input()

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

    counter = 1 if ("7" in now and "5" in now and "3" in now) else 0
    for i in "357":
        counter += dfs(now + i)

    return counter

print(dfs("0"))

Solution (Python):

ans = 0

def check(num_str):
    for i in ['7', '5', '3']:
        if i not in num_str:
            return 0
    return 1

def make_data(num, num_str):
    global ans
    if num < int(num_str):
        return
    if check(num_str):
        ans += 1

    make_data(num, num_str + '7')
    make_data(num, num_str + '5')
    make_data(num, num_str + '3')


def main():
    num = int(input())
    make_data(num, '0')

    global ans
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
l=len(str(n))
if l<3:
  print(0)
else:
  ans=set()
  b=[0,3,5,7]
  for i in range(4**l-1):
    a=0
    c=1
    while i>0:
      a+=c*b[i%4]
      i//=4
      c*=10
    if "3" in str(a) and "5" in str(a) and "7" in str(a):
      if n>=a:
        if "0"not in str(a):
          ans.add(a)
  print(len(ans))

Solution (Python):
from collections import deque


def bfs(parent, n):
    queue = deque()
    queue.append(parent)
    d = ['3', '5', '7']
    ans = 0

    while queue:
        s = queue.popleft()
        for di in d:
            t = s+di
            if n < int(t):
                return ans
            elif int(t) <= n and '3' in t \
                    and '5' in t and '7' in t:
                ans += 1

            queue.append(t)


if __name__ == "__main__":
    n = int(input())

    print(bfs('3', n)+bfs('5', n)+bfs('7', n))

Solution (Python):
import itertools

n = int(input())
num = ['3','5','7']
elements = []
for i in range(1,len(str(n))+1):
    options = itertools.product(num, repeat=i)
    for s in options:
        num1 = ''.join(s)
        elements.append(num1)

cnt = 0

for i in range(len(elements)):
    if int(elements[i]) <= n:
        if '3' in elements[i] and '5' in elements[i] and '7' in elements[i]:
            cnt += 1
    else:
        break

print(cnt)

Solution (Python):

import itertools
n = int(input())
nums = []
pre_nums = ['3','5','7']

for i in range(3,10):
    for ids in itertools.product(pre_nums, repeat=i):
        if '3' in ids and '5' in ids and '7' in ids:
            nums.append(int(''.join(ids)))
for i,num in enumerate(nums):
    if n < num:
        print(i)
        break
else:
    print(len(nums))

Solution (Python):
N = int(input())
def check(x):
    x = str(x)
    return x.count("3") >= 1 and x.count("5") >= 1 and x.count("7") >= 1
def dfs(x):
    if x > N or x >= 10**9:
        return 0
    ans = 0
    ans += int(check(x))

    ans += dfs(10 * x + 3)
    ans += dfs(10 * x + 5)
    ans += dfs(10 * x + 7)
    return ans
print(dfs(0))

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


def dfs(s):
    if s and int(s) > n:
        return 0
    if '3' in s and '5' in s and '7' in s:
        return dfs(s + '3') + dfs(s + '5') + dfs(s + '7') + 1
    else:
        return dfs(s + '3') + dfs(s + '5') + dfs(s + '7')


print(dfs(''))

Solution (Python):
import itertools

n = int(input())

ans = 0
for r in range(1, 10):
    for s in itertools.product('357', repeat=r):
        d = int(''.join(s))
        if '3' in s and '5' in s and '7' in s and d <= n:
            ans += 1

print(ans)

Solution (Python):
N = int(raw_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
from pprint import pprint



def solve(N: int):
    s = str(N + 1)
    n = len(s)
    
    dp = [[[[[[0 for _ in range(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 in range(0, n):
        for smaller in range(2):
            for started in range(2):
                for i1 in range(2):
                    for i2 in range(2):
                        for i3 in range(2):
                            for nex in [0, 3, 5, 7]:
                                if not smaller and nex > int(s[i]):
                                    
                                    continue
                                if started and nex == 0:
                                    continue
                                
                                
                                
                                
                                
                                
                                
                                

                                
                                dp[i + 1][smaller or nex < int(s[i])][started or nex > 0][i1 or nex == 3][i2 or nex == 5][i3 or nex == 7] += \
                                    dp[i][smaller][started][i1][i2][i3]
        
        
    ret = dp[n][1][1][1][1][1]
    
    print(ret)
    return


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

if __name__ == '__main__':
    main()

Solution (Python):

import sys
from pprint import pprint



def solve(N: int):
    s = str(N + 1)
    n = len(s)
    
    dp = [[[[[[0 for _ in range(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 in range(0, n):
        for smaller in range(2):
            for started in range(2):
                for i1 in range(2):
                    for i2 in range(2):
                        for i3 in range(2):
                            for nex in [0, 3, 5, 7]:
                                if not smaller and nex > int(s[i]):
                                    
                                    continue
                                if started and nex == 0:
                                    continue
                                
                                
                                
                                
                                
                                
                                
                                

                                
                                dp[i + 1][smaller or nex < int(s[i])][started or nex > 0][i1 or nex == 3][i2 or nex == 5][i3 or nex == 7] += \
                                    dp[i][smaller][started][i1][i2][i3]
        
        
    ret = dp[n][1][1][1][1][1]
    
    print(ret)
    return


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

if __name__ == '__main__':
    main()

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

Solution (Python):

from collections import Counter
N = int(input())
l = ["0", "3", "5", "7"]
ans = ["0"] * 9
cnt = 0
for a in l:
    ans[0] = a
    for b in l:
        ans[1] = b
        for c in l:
            ans[2] = c
            for d in l:
                ans[3] = d
                for e in l:
                    ans[4] = e
                    for f in l:
                        ans[5] = f
                        for g in l:
                            ans[6] = g
                            for h in l:
                                ans[7] = h
                                for i in l:
                                    ans[8] = i
                                    ans_i = int("".join(ans))
                                    ans_c = Counter(str(ans_i))
                                    if ans_i <= N and "0" not in str(ans_i) and len(ans_c.keys()) == 3 and len(str(ans_i)) >= 3:
                                        cnt += 1
print(cnt)

Solution (Python):

import sys
import math

def dfs(N: int, digit: int,cur: str):
    if len(cur) < digit:
        return dfs(N,digit,cur+"3") + dfs(N,digit,cur+"7") + dfs(N,digit,cur+"5")
    else:
        if int(cur) > N:
            return 0
        if cur.count("3") > 0 and cur.count("7") > 0 and cur.count("5"):
            return 1
        else:
            return 0


def solve(N: int):
    digit = math.ceil(math.log10(N))
    sum = 0
    for i in range(3,digit+1):
        sum += dfs(N,i,"")
    print(sum)
    return



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

if __name__ == '__main__':
    main()

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

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

print(dfs(''))

Solution (Python):

import sys
import functools
import itertools
INF = float("inf")


@functools.lru_cache(maxsize=None)
def pow(b, n):
    return b**n


def f(n):
    
    if n < 3:
        return 0

    return pow(3, n) - 3*pow(2, n) + 3


def solve(N: int):
    ketamax = len(str(N))

    ans = 0
    
    for i in range(3, ketamax):
        ans += f(i)
    
    
    for item in itertools.product(["3", "5", "7"], repeat=ketamax):
        if "3" not in item or "5" not in item or "7" not in item:
            continue
        elif int("".join(item)) > N:
            continue
        else:
            ans += 1
    print(ans)
    return


def main():

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


if __name__ == '__main__':
    main()

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

def count(i,x,y,z):
	if i > N:
		return 0
	c = 1 if x * y * z > 0 else 0
	c += count(i*10+7, x+1, y, z)
	c += count(i*10+5, x, y+1, z)
	c += count(i*10+3, x, y, z+1)
	return c

print(count(0,0,0,0))

Solution (Python):
n = int(input())
def counter(num1, num2):
	if num2 == "0":
		num21 = "3"
		num22 = "5"
		num23 = "7"
		return counter(num1, num21) + counter(num1, num22) + counter(num1, num23)
	elif int(num2) > num1:
		return 0
	else:
		result = 0
		num21 = "3" + num2
		num22 = "5" + num2
		num23 = "7" + num2
		if "3" in num21 and "5" in num21 and "7" in num21 and int(num21) <= num1:
			result += 1
		if "3" in num22 and "5" in num22 and "7" in num22 and int(num22) <= num1:
			result += 1
		if "3" in num23 and "5" in num23 and "7" in num23 and int(num23) <= num1:
			result += 1
		return counter(num1, num21) + counter(num1, num22) + counter(num1, num23) + result

print(counter(n, "0"))

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

def dfs(s):
    if len(s)==len(str(N)):
        return 0
    ans=0
    for c in "357":
        if int(s+c)<=N and all(a in s+c for a in "357"):
            ans+=1
        ans+=dfs(s+c)
    return ans
print(dfs(''))

Solution (Python):
n=int(input())
import bisect
import itertools
l=len(str(n))
ans=[]
num=[]
x=['3', '5', '7']
for k in range(3,l+1):
    m=list(itertools.product(x, repeat=k))
    num.extend(m)
for i in range(len(num)):
    y=num[i]
    if '3' in y and '5' in y and '7' in y:
        number=''
        for j in range(len(y)):
            number+=y[j]
        ans.append(int(number))
ans.sort()
print(bisect.bisect_right(ans, n))

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


def dfs(s):
    if int(s) > N:
        return 0
    ct = 1 if all(s.count(a) for a in '357') else 0
    ct += dfs(s+'3')
    ct += dfs(s+'5')
    ct += dfs(s+'7')
    return ct


print(dfs('0'))

Solution (Python):
def makestr(lst):
	s = ''
	for i in range(0, len(lst)):
		s = s + lst[i]
	return s

N = int(raw_input())
queue = [[]]
cnt = 0
while(True):
	now = queue.pop(0)
	if now != []:
		if int(makestr(now)) > N: break
		elif '3' in now and '5' in now and '7' in now:
			cnt += 1
	lst = ['3', '5', '7']
	for i in range(0, 3):
		next = []
		for j in range(0, len(now)):
			next.append(now[j])
		next.append(lst[i])
		queue.append(next)

print cnt

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

le = len(str(N))
al = ['3','5','7']
al2 = []
for i in range(le-1):
    al1 = []
    for n in al:
        a = int(str(n)+'3')
        b = int(str(n)+'5')
        c = int(str(n)+'7')
        al1.append(a)
        al1.append(b)
        al1.append(c)
        al2.append(a)
        al2.append(b)
        al2.append(c)
    al = al1

cnt = 0
for n in al2:
    if n <= N:
        if all(str(n).count(c) > 0 for c in '753'):
            cnt += 1

print(cnt)

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

le = len(str(N))
al = ['3','5','7']
al2 = []
for i in range(le-1):
    al1 = []
    for n in al:
        a = int(str(n)+'3')
        b = int(str(n)+'5')
        c = int(str(n)+'7')
        al1.append(a)
        al1.append(b)
        al1.append(c)
        al2.append(a)
        al2.append(b)
        al2.append(c)
    al = al1

cnt = 0
for n in al2:
    if n <= N:
        if all(str(n).count(c) > 0 for c in '753'):
            cnt += 1

print(cnt)

Solution (Python):
import itertools
ans = 0
nums = []
N = int(input())
for k in range(1, 10):
    s = itertools.product(['3', '5', '7'], repeat = k)
    for seq in s:
        num = ''.join(seq)
        nums.append(num)
for num in nums:
    if '3' in num and '5' in num and '7' in num and int(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):
import itertools
n=int(input())

keta=len(str(n))
hako=[]
for i in range(3,keta+1):
    for c in list(itertools.product(["7","5","3"],repeat=i)):
        if len(set(c))==3:
            a=int("".join(c))
            hako.append(a)
if n in hako:
    hako.sort()
    k=hako.index(n)
    b=hako[:k]
    print(len(b)+1) 
else:
    hako.append(n)
    hako.sort()
    k=hako.index(n)
    b=hako[:k]
    print(int(len(b)))

Solution (Python):
def main():
	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"))

if __name__ == '__main__':
    main()

Solution (Python):
def check(x):
    str_x = str(x)
    if min(str_x.count("3"),str_x.count("5"),str_x.count("7")) > 0:
        return True
    else:
        return False

def solve(x):
    if x > N:
        return 0
    if check(x):
        ans = 1
    else :
        ans = 0
    ans += solve(10*x + 3)
    ans += solve(10*x + 5)
    ans += solve(10*x + 7)
    return ans
N = int(input())
print(solve(0))

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

def dfs(x):
    if x > N:
        return 0

    san, go, nana = 0, 0, 0
    c = x
    for i in range(len(str(c))):
        if c % 10 == 3:
            san += 1
        elif c % 10 == 5:
            go += 1
        elif c % 10 == 7:
            nana += 1
        c = c // 10
    if san > 0 and go > 0 and nana > 0:
        ret = 1
    else:
        ret = 0

    for i in [3, 5, 7]:
        ret += dfs(10*x + 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):
from itertools import product
n = int(input())
cnt = 0
for i in range(3, len(str(n))+1):
	for p in product(["7","5","3"], repeat = i):
		if len(set(p)) == 3:
			p = int("".join(p))
			if p <= n:
				cnt += 1
print(cnt)

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 x == "":
		continue
	elif len(set(x)) < 3:
		continue
	elif int(x) not in A and int(x) <= n:
		A.add(int(x))
print(len(A))

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 = input()
digit = len(n)
n = int(n)

def make753(num):
    cand = [""]
    endj = 0
    for i in range(num):
        for j in range(endj,3 ** i + endj):
            cand.append(cand[j] + "7")
            cand.append(cand[j] + "5")
            cand.append(cand[j] + "3")
            endj = j + 1
    del cand[0]
    return cand

cand = make753(digit)

delete = []
for i in range(len(cand)):
    if "3" not in cand[i] or "5" not in cand[i] or "7" not in cand[i]:
        delete.append(i)

diff = 0
for i in range(len(delete)):
    del cand[delete[i] - diff]
    diff += 1

for i in range(len(cand)):
    cand[i] = int(cand[i])

cand.sort()

for i in range(len(cand)):
    if n < cand[i]:
        print(i)
        break
else:
    print(len(cand))

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())
res = 0
def is753(N):
    n7,n5,n3 = 0,0,0
    while N > 0:
      if N % 10 == 7:
          n7 = 1
      elif N%10 == 5:
          n5 = 1
      else:
          n3 = 1
      N = N // 10
    return n5 & n3 & n7

def solve(D):
	if D > N:
		return 0
	else:
		d = 0
		if is753(D):
			d = 1
		return solve(D*10+3) +  solve(D*10+5) + solve(D*10+7) + d
print(solve(0))

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

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

def dfs(s):
    global ans
    if int(s) > N:
        return

    if all(s.count(c) for c in '753'):
        ans += 1
    
    dfs(s + '7')
    dfs(s + '5')
    dfs(s + '3')

dfs('0')

print(ans)

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

def dfs(s):
    global ans
    if int(s) > N:
        return

    if s.count('7') and s.count('5') and s.count('3'):
        ans += 1
    
    dfs(s + '7')
    dfs(s + '5')
    dfs(s + '3')

dfs('0')

print(ans)

Solution (Python):
import itertools

N = int(input())

count = 0
for n in range(3, 10):
    for p in itertools.product(['3', '5', '7'], repeat=n):
        pstr = ''.join(p)
        if len(set(pstr)) < 3 or int(pstr) > N:
            continue
        count += 1
print(count)

Solution (Python):
n = int(input())
def calc(t):
    if int(t) > n:
        return 0
    if (("3" in t) & ("5" in t) & ("7" in t)):
        ret = 1
    else:
        ret = 0
    for c in "357":
        ret += calc(t+c)
    return ret

print(calc("0"))

Solution (Python):
from itertools import product
N = int(input())
ans = 0
for l in range(1, 11):
    for p in product("357", repeat=l):
        v = "".join(p)
        if "3" in v and "5" in v and "7" in v and int("".join(p)) <= N:
            ans += 1
print(ans)

Solution (Python):
def f753():
    s=["3","5","5"]
    while 1:
        lens=len(s)
        for i in range(lens-1,-1,-1):
            if s[i]!="7":
                s[i]="5" if s[i]=="3" else "7"
                for ii in range(i+1,lens):
                    s[ii]="3"
                break
        else:
            s=["3"]*(lens-1)+["5","7"]
        if len(set(s))<3:continue
        yield int("".join(s))

n=int(input())
cnt=0
for n753 in f753():
    if n753>n:break
    cnt+=1

print(cnt)

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

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

print(cal("3")+cal("5")+cal("7"))

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

N = int(input())
ans = 0

for j in range(3, int(math.log10(N))+2):
    list753 = [['3', '5', '7'] for _ in range(j)]
    for i in product(*list753):
        if ('3' in i) and ('5' in i) and ('7' in i) and int(''.join(i)) <= N:
            ans += 1
        else:
            continue

print(ans)

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

Solution (Python):
N = int(input())
nums = []
length = len(str(N))
def dfs(s, n):
        global nums
        nums.append(s)
        if n == length:
                return
        dfs(s + "3", n + 1)
        dfs(s + "5", n + 1)
        dfs(s + "7", n + 1)

dfs("", 0)
ans = 0
for i in nums:
        if i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1:
                if int(i) <= N:
                        ans += 1
print(ans)

Solution (Python):
count = 0
N = 0
def make753num(num):
    global count
    global N
    if num > N:
        return
    if num >= 357 and min(str(num).count('3'), str(num).count('5'), str(num).count('7')) >= 1:
        count += 1
    make753num(num * 10 + 3)
    make753num(num * 10 + 5)
    make753num(num * 10 + 7)
def main():
    global count
    global N
    N = int(input())
    make753num(0)
    print(count)
main()

Solution (Python):
N = int(input())
L = ['3','5','7']
K = str(N)
for i in range(len(K)):
  T = len(L)
  for j in range(T):
    L.append(L[j]+'3')
    L.append(L[j]+'5')
    L.append(L[j]+'7')
  L = list(set(L))
ans = 0
for i in range(len(L)):
  cnt3 = 0
  cnt5 = 0
  cnt7 = 0
  for j in range(len(L[i])):
    if L[i][j] == '3':
      cnt3 += 1
    elif L[i][j] == '5':
      cnt5 += 1
    else:
      cnt7 += 1
  if cnt3 > 0 and cnt5 > 0 and cnt7 > 0:
    if int(L[i]) <= N:
      ans += 1
print(ans)

Solution (Python):
from itertools import product
N = input()
length = len(N)
T = [''.join(t) for t in product(('3','5','7'),repeat = 3)]

def f(N,s):
    if len(s) == length:
        if int(s) <= int(N) and '3' in s and '5' in s and '7' in s:
            return 1
        else:
            return 0
    else:
        if '3' in s and '5' in s and '7' in s:
            a = 1
        else:
            a = 0
        a += sum(f(N,s+c) for c in('3','5','7'))
        return a
if int(N)<357:
    print(0)
else:
    print(sum(f(N, t) for t in T))

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
  if all(s.count(i)>0 for i in '753'):
    ans=1
  else:
    ans=0
  for i in '753':
    ans+=dfs(s+i)
  return ans
print(dfs('0'))

Solution (Python):
import itertools

n_str = input()
n = int(n_str)
digits = len(n_str)
nums = ('3', '5', '7')
count = 0
for i in range(3, digits + 1):
    for strs in itertools.product(*[nums]*i):
        m = int(''.join(strs))
        if ('3' in strs) and ('5' in strs) and ('7' in strs) and m <= n:
            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 numpy as np
from itertools import product
s = input()
n = int(s)

digit = len(s)

selected_num = []
for order in range(3, 10, 1):
    for i in product('753', repeat = order):
        concat_str = "".join(i)
        if(('7' in concat_str) and ('5' in concat_str) and ('3' in concat_str)): 
            selected_num.append(int(concat_str))

selected_num_array = np.array(selected_num)

print(np.sum(selected_num_array <= n))

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

print(dfs('0'))

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

Solution (Python):
n=int(input())
s=[]
def dfs(string,cur):
  if cur==len(str(n)):
    if string.count('3')>0 and string.count('5')>0 and string.count('7'):
      s.append(string)
    return
  dfs(string+"",cur+1)
  dfs(string+"7",cur+1)
  dfs(string+"5",cur+1)
  dfs(string+"3",cur+1)
dfs("",0)

cnt=0
for i in set(s):
  if int(i)<=n:
    cnt+=1
print(cnt)

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

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