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):


from itertools import product

N = int(input())

cnt = 0

for prod in product(['0', '3', '5', '7'], repeat=9):
    
    num = int(''.join(prod))
    s = str(num)
    
    if (s.find('3') == -1 or s.find('5') == -1
            or s.find('7') == -1 or s.find('0') != -1):
        continue
    
    if num > N:
        continue
    cnt += 1
print(cnt)

Solution (Python):


from itertools import product

N = int(input())

cnt = 0

for prod in product(['0', '3', '5', '7'], repeat=10):
    
    num = int(''.join(prod))
    s = str(num)
    
    if (s.find('3') == -1 or s.find('5') == -1
            or s.find('7') == -1 or s.find('0') != -1):
        continue
    
    if num > N:
        continue
    cnt += 1
print(cnt)

Solution (Python):


from itertools import product

N = int(input())

cnt = 0

for prod in product(['0', '3', '5', '7'], repeat=10):
    
    num = int(''.join(prod))
    s = str(num)
    
    if (s.find('3') == -1 or s.find('5') == -1
            or s.find('7') == -1 or s.find('0') != -1):
        continue
    
    if num > N:
        continue
    cnt += 1
print(cnt)

Solution (Python):
def str10to3(x):
    a = ""
    while x >= 3:
        a += str(x % 3)
        x = x / 3
    a += str(x % 3)
    return "".join(reversed(a))


def str3to10(x):
    num_753 = ['7', '5', '3']
    return "".join([num_753[int(i)] for i in x])


N = input()
c = 0
for i in range(3 ** 10):
    num_753 = str3to10(str10to3(i))
    for i in range(9):
        if int('7' * i + num_753) <= N and set('7' * i + num_753) == set(['7', '5', '3']):
            c += 1
print c

Solution (Python):
import itertools
N = int(input())
nums = set([7,5,3])
n = 0
for i in range(8):
    li = list(nums)
    for youso in li:
        nums.add(youso * 10 + 3)
        nums.add(youso * 10 + 5)
        nums.add(youso * 10 + 7)
li753 = list()
for i in nums:
    s = str(i)
    if '3' in s and '5' in s and '7' in s:
        li753.append(i)
ans = 0
for i in li753:
    if N >= i: ans += 1
print(ans)

Solution (Python):
import itertools as t

N = int(input())

L = [ int(''.join(j)) for i in range(10) for j in t.product(['3','5','7'], repeat=i) if '3' in j and '5' in j and '7' in j]
L = [i for i in L if i <= N]
print(len(L))

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

def check_753(s):
  s = str(int(s))
  a = ''.join(sorted(list(set(s))))
  if a == '357':
    return True
  else:
    return False

def shi(s):
  if int(s) > N:
    return 0
  if check_753(s):
    ret = 1
  else:
    ret = 0
  for i in '753':
    ret += shi(s+i)
  return ret

print(shi('0'))

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

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

print(dfs('0'))

Solution (Python):
def gen(n, l, m):
    l7 = list(map(lambda x: "7" + x, l))
    l5 = list(map(lambda x: "5" + x, l))
    l3 = list(map(lambda x: "3" + x, l))
    res = l7 + l5 + l3 + l
    m = m * 10 + 7
    if m > n:
        return res
    else:
        return gen(n, res, m)

n = int(input())
l = list(gen(n, [""], 0))
l = list(filter(lambda x : "7" in x and "5" in x and "3" in x, l))
l = list(set(l))
l = list(map(int, l))
l = list(filter(lambda x : x <= n, l))
print (len(l))

Solution (Python):
n = int(input())
def solve(s):
	if int(s)>n:
		return 0
	if s.count('7')>0 and s.count('5')>0 and s.count('3')>0:
		return 1 + solve(s+'7') + solve(s+'5') + solve(s+'3')
	else:
		return solve(s+'7') + solve(s+'5') + solve(s+'3')
print(solve('0'))

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

def iter_nums():
    xs = "357"
    while 1:
        for x in xs:
            yield x
        xs = [n + x for n in "357" for x in xs]

result = 0
for s in iter_nums():
    n = int(s)
    if n > N:
        break
    if "3" in s and "5" in s and "7" in s:
        result += 1

print(result)

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

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

nums = [3, 5, 7]

def iter_nums():
    xs = nums
    base = 10
    while 1:
        for x in xs:
            yield x
        xs = [n * base + x for n in nums for x in xs]
        base *= 10

def calc(N):
    result = 0
    for n in iter_nums():
        if n > N:
            break
        s = str(n)
        if "3" in s and "5" in s and "7" in s:
            result += 1
    return result

result = calc(N)

print(result)

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


seq = [3,5,7]

memo = [0] * digits
memo[0] = [(3,), (5,), (7,)]
count = 0
for n in range(2, digits+1):
    index = n - 1
    memo[index] = []
    before_digit = n - 1
    before_index= index - 1
    before_357s = memo[before_index]
    for before_357 in before_357s:
        for sgn in seq:
            memo[index].append(tuple(list(before_357) + [sgn]))
    memo[index] = list(set(memo[index]))

    ans_list = filter(lambda t: 3 in t and 5 in t and 7 in t, memo[index])
    ans_list = map(lambda t: int(''.join(list(map(lambda i: str(i), t)))), ans_list)
    ans_list = list(filter(lambda n: n <= N, ans_list))
    count += len(ans_list)

print(count)

Solution (Python):
from bisect import bisect_right
from itertools import product, chain

N = int(input())


l = list(chain(*[[int("".join(m)) for m in product("357", repeat=i) if set(m) == {"3", "5", "7"}] for i in range(1, len(str(N))+1)]))

print(bisect_right(l, N))

Solution (Python):
all_list = [[3],[5],[7]]
num = [3,5,7]
inp = int(input())
for j in all_list:
    for i in num:
        a = [x for x in j]
        a.append(i)
        all_list.append(a)
    if len(all_list[-1]) > 10:
        break
    
count = 0

for l in all_list:
    strlist = list(map(str,l))
    joinlist = ''.join(strlist)
    number = int(joinlist)
    if number > inp:
        break
    if l.count(7) * l.count(5) * l.count(3) != 0:
        count += 1
        
print(count)

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

d={}

def c(s):
	a = [0] * 10
	for i in s:
		a[int(i)] += 1
	if a[3] != 0 and a[5] != 0 and a[7] != 0:
		return True
	else:
		return False

def r(m, s):
	global d
	if s == "":
		pass
	elif m < int(s) or (s in d):
		return 0
	ret = 0
	if c(s):
		ret += 1
	d[s] = 1
	ret += r(m,s+"3")
	ret += r(m,s+"5")
	ret += r(m,s+"7")
	ret += r(m,"3"+s)
	ret += r(m,"5"+s)
	ret += r(m,"7"+s)
	return ret

def main():
	n = int(input())
	print(r(n,""))
	return
main()

Solution (Python):
class Handle753:
    def __init__(self, N):
        self.N = N
        self.ans = 0


    def judge753(self, x):
        counter = [False for _ in range(10)]
        while x > 0:
            a = x % 10
            counter[a] = True
            x //= 10

        for j, c in enumerate(counter):
            if j in (3, 5, 7):
                if not c:
                    return False
            else:
                if c:
                    return False
        
        return True


    def dfs(self, x=0):
        if x > self.N:
            return
        if self.judge753(x):
            self.ans += 1
        self.dfs(10 * x + 3)
        self.dfs(10 * x + 5)
        self.dfs(10 * x + 7)


    def show_answer(self):
        print(self.ans)


def main():
    N = int(input())
    hoge = Handle753(N)
    hoge.dfs()
    hoge.show_answer()


if __name__ == "__main__":
    main()

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

def judge753(x):
    counter = [False for _ in range(10)]
    while x > 0:
        a = x % 10
        counter[a] = True
        x //= 10

    for j, c in enumerate(counter):
        if j in (3, 5, 7):
            if not c:
                return False
        else:
            if c:
                return False
    
    return True


def dfs(x=0):
    if x > N:
        return
    global ans
    if judge753(x):
        ans += 1
    dfs(10 * x + 3)
    dfs(10 * x + 5)
    dfs(10 * x + 7)

dfs()
print(ans)

Solution (Python):
n = input()
mat = ["3","5","7"]
l = []
l_753 = []

def dfs(i, s):
    if i == len(n):
        l.append(int(s))
        return
    
    for m in mat:
        dfs(i+1, s+m)

for i_ in range(len(n)):
    dfs(len(n)-i_-1, "")

for a in l:
    if "3" in str(a) and "5" in str(a) and "7" in str(a):
        l_753.append(a)

l_753.append(int(n)+1)
l_753.sort()
print(l_753.index(int(n)+1))

Solution (Python):

N = int(input())
import math 

num = 0
def f(st):
    global num
    if int(st) > N:
        return 
    else:
        if '3' in st and '5' in st and '7' in st:
            num += 1
    for c in '753':
        f(st + c)


f("0")
print(num)

Solution (Python):
def next_num(num):
	if num == 0:
		return 3
	elif num % 10 == 3:
		return num + 2
	elif num % 10 == 5:
		return num + 2
	elif num % 10 == 7:
		return next_num(num//10) * 10 + 3

def is_357(num):
	flg = [False for i in range(3)]
	num = str(num)
	for c in num:
		if c == '3':
			flg[0] = True
		elif c == '5':
			flg[1] = True
		elif c == '7':
			flg[2] = True
		else:
			return False
	return all(flg)



N = int(input())

num = 357
counter = 0

while num <= N:
	if is_357(num):
		counter += 1
	
	digit = num % 10
	
	if digit == 3 or digit == 5:
		num += 2
	else:
		num = next_num(num)


print(counter)

Solution (Python):
def nexti(i):
    if i == 0:
        return 3
    elif i % 10 == 3:
        return i + 2
    elif i % 10== 5:
        return i + 2
    elif i % 10 ==7:
        return nexti(i//10)*10 + 3

n = int(input())
nn = 0
i = 357

while i <= n:
  s = str(i)
  if '3' in s:
    if '5' in s:
      if '7' in s:
        
        nn += 1
  if i % 10 == 7:
    i = nexti(i)
  else:
    i +=2
print(nn)

Solution (Python):
def nextn(n):
    if n == 0:
        return 3
    elif n % 10 == 3:
        return n+2
    elif n % 10== 5:
        return n+2
    elif n % 10 ==7:
        return nextn(n//10)*10 + 3

N = int(input())
n = 357
ans = 0
while n <= N:
    s = str(n)
    a = [False,False,False]
    for c in s:
        if c == '3':
            a[0] = True
        elif c == '5':
            a[1] = True
        elif c == '7':
            a[2] = True
        else:
            print(s)
    if all(a):
        ans += 1
    n = nextn(n) 
print(ans)

Solution (Python):
def nextn(n):
    if n == 0:
        return 3
    elif n % 10 == 3:
        return n+2
    elif n % 10== 5:
        return n+2
    elif n % 10 ==7:
        return nextn(n//10)*10 + 3

N = int(input())
n = 357
ans = 0
while n <= N:
    s = str(n)
    a = [False,False,False]
    for c in s:
        if c == '3':
            a[0] = True
        elif c == '5':
            a[1] = True
        elif c == '7':
            a[2] = True
        else:
            print(s)
    if all(a):
        ans += 1
    n = nextn(n) 
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(s):
    if int(s) > N:
        return 0

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

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

    return count

print(dfs('0'))

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

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

Solution (Python):






def sgs(s:str)->bool:
    return True if all( s.count(c)>0 for c in "753") else False





n = int( input() )


def recursive(s:str)->int:
    if n < int(s):
        return 0

    ret = 1 if sgs(s) else 0

    for x in "753":
       ret += recursive( s + x )
    
    return ret

print( recursive('0') )

Solution (Python):
N = input()
import itertools
li = []
for v in itertools.product('0357', repeat=len(N)):
    a = ''
    for w in v:
        a = a + w
    li.append(a)

li2 = []
for v in li:
    if '3' in v and '5' in v and '7' in v and int(v) <= int(N):
        v = v.replace('0', '')
        li2.append(v)
    else: pass
print(len(set(li2)))

Solution (Python):
n=int(input())
c=0
l=['0','3','5','7']
for i1 in l:
 for i2 in l:
  for i3 in l:
   for i4 in l:
    for i5 in l:
     for i6 in l:
      for i7 in l:
       for i8 in l:
        for i9 in l:
         x=str(int(i1+i2+i3+i4+i5+i6+i7+i8+i9))
         if '3' in x and '5' in x and '7' in x and '0' not in x and int(x)<=n:c+=1
print(c)

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

def dfs(s):
    if int(s) > N:
        return 0
    res = 0
    flag = True
    for c in '753':
        if s.count(c) == 0:
            flag = False
    res =  1 if flag else 0
    for c in '753':
        res += dfs(s+c)
    return res

print(dfs('0'))

Solution (Python):
n=int(input())
c=0
l=[0,3,5,7]
for i1 in l:
 for i2 in l:
  for i3 in l:
   for i4 in l:
    for i5 in l:
     for i6 in l:
      for i7 in l:
       for i8 in l:
        for i9 in l:
         x=str(i1+10*i2+100*i3+1000*i4+10**4*i5+10**5*i6+10**6*i7+10**7*i8+10**8*i9)
         if '3' in x and '5' in x and '7' in x and '0' not in x and int(x)<=n:c+=1
print(c)

Solution (Python):
n=int(input())
c=0
l=[0,3,5,7]
for i1 in l:
 for i2 in l:
  for i3 in l:
   for i4 in l:
    for i5 in l:
     for i6 in l:
      for i7 in l:
       for i8 in l:
        for i9 in l:
         x=str(i1+10*i2+100*i3+1000*i4+10000*i5+100000*i6+1000000*i7+10000000*i8+100000000*i9)
         if '3' in x and '5' in x and '7' in x and '0' not in x and int(x)<=n:c+=1
print(c)

Solution (Python):

S = input()
N = int(S)


def count753(s):
    is753 = "7" in s and "5" in s and "3" in s
    if len(s) == len(S):
        return 1 if int(s) <= N and is753 else 0
    return int(is753) + count753(s + "7") + count753(s + "5") + count753(s + "3")


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

Solution (Python):
from itertools import product

NS = input()
N = int(NS)
D = len(NS)

arr = ['0', '3', '5', '7']
ans = 0

for d in [int(''.join(dd)) for dd in product(arr, repeat=D) if '3' in dd and '5' in dd and '7' in dd]:
    if '0' in str(d):
        continue
    if d > N:
        break
    ans += 1

print(ans)

Solution (Python):
s = input()

n = int(s)

a = []
total = 0


def is_753(a):
    return set(a) == set([7,5,3])

def get_int(a):
    result = 0
    for i in range(len(a)):
        result = result * 10 + a[len(a) - i - 1]
    return result

def dfs(a, k):
    global total
    if is_753(a):
        total += 1
    for next_x in [3,5,7]:
        a.append(next_x)
        if get_int(a) <= k:
            dfs(a, k)
            a.pop()
        else:
            a.pop()
            break

dfs(a, n)
print(total)

Solution (Python):
from itertools import product

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

for i in range(3, 10):
    for t in (product(num_list, repeat=i)):
        check = t.count("3")*t.count("5")*t.count("7")
        if int("".join(t)) <= N and check:
            count += 1


print(count)

Solution (Python):


n = int(input())


k = 357


def check(v):
    s = str(v)
    if s.find('3') != -1 and s.find('5') != -1 and s.find('7') != -1:
        return 1
    return 0

def next(x):

    i = x % 10
    if (i == 3):
        return x + 2 
    if (i == 5):
        return x + 2
    if (i == 7):
        if x >= 10:
            q = next(int(x / 10))
        else:
            q = 3
        return q * 10 + 3

count = 0
while k <= n:
    c = check(k)
    if c:
        count = count + 1

    k = next(k)

print(count)

Solution (Python):
n=int(input())
c=0
l=[3,5,7]
L=[]
for i1 in l:
  for i2 in l:
    for i3 in l:
      for i4 in l:
        for i5 in l:
          L.append(10000*i1+1000*i2+100*i3+10*i4+i5)
for i in range(min(n+1,10000)):
  l=str(i)
  if '3' in l and '5' in l and '7' in l and '0' not in l and '1' not in l and '2' not in l and '4' not in l and '6' not in l and '8' not in l and '9' not in l:c+=1
for j in L:
  for i in range(j,n+1,100000):
    l=str(i)
    if '3' in l and '5' in l and '7' in l and '0' not in l and '1' not in l and '2' not in l and '4' not in l and '6' not in l and '8' not in l and '9' not in l:c+=1
print(c)

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

def judge(x):
    y = x
    f3 = 0
    f5 = 0
    f7 = 0
    while y :
        kk = y%10
        if kk == 3:
            f3 = 1
        elif kk == 5:
            f5 = 1
        elif kk == 7:
            f7 = 1
        else:
            return 0
        y = y//10
    return f3 and f5 and f7
def dfs(x,y):
    if x > n:
        return 0
    ans = judge(x)
    ans += dfs(x * 10 + 7, n)
    ans += dfs(x * 10 + 5, n)
    ans += dfs(x * 10 + 3, n)
    return ans
print(dfs(0,n))

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):

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, = map(int, raw_input().split())
M = len(str(N))
r = 0
for i in range(1, M+1):
  for s in product("357", repeat=i):
    x = int("".join(s))
    if "3" in s and "5" in s and "7" in s and x <= N:
      r += 1
print r

Solution (Python):
from functools import lru_cache
@lru_cache(maxsize=1000)
def digit_search(k, tight, own, X, started):
    if k == len(X):
        return int(own==7)

    digit = int(X[k])
    lim = digit if tight else 9
    res = 0
    for i in range(lim+1):
        if started:
            if i!=3 and i!=5 and i!=7: continue
        else:
            if i!=0 and i!=3 and i!=5 and i!=7: continue

        res += digit_search(k+1, tight and digit==i,\
                            own | (i==7)*4 | (i==5)*2 | (i==3),\
                            X, started or i!=0)

    return res

print(digit_search(0, True, 0, input(), False))

Solution (Python):
num753 = []
num753.append([0,0,0,0,0,0,0])  
num753.append([1,1,1,0,0,0,0])

for i in range(1,10):
    num753.append([num753[i][0],num753[i][1],num753[i][2],num753[i][0]+num753[i][1]+num753[i][3]*2,num753[i][0]+num753[i][2]+num753[i][4]*2,num753[i][1]+num753[i][2]+num753[i][5]*2,num753[i][3]+num753[i][4]+num753[i][5]+num753[i][6]*3])

N = input()

ans = 0
for i in range(len(N)):
    ans += num753[i][6]

check3 = False
check5 = False
check7 = False
for i in range(len(N)):
    if int(N[i])<3:
        break
    if int(N[i])==3:
        if i==len(N)-1:
            if check5 and check7:
              ans += 1
        check3 = True
        continue
    ans += num753[len(N)-i-1][5]+num753[len(N)-i-1][6]
    if check5:
        ans += num753[len(N)-i-1][2]+num753[len(N)-i-1][4]
    if check7:
        ans += num753[len(N)-i-1][1]+num753[len(N)-i-1][3]
    if check5 and check7:
        ans += num753[len(N)-i-1][0]
    if int(N[i])<5:
        break
    if int(N[i])==5:
        if i==len(N)-1:
            if check5 and check7:
                ans += 1
            if check3 and check7:
                ans += 1
        check5 = True
        continue
    ans += num753[len(N)-i-1][4]+num753[len(N)-i-1][6]
    if check3:
        ans += num753[len(N)-i-1][2]+num753[len(N)-i-1][5]
    if check7:
        ans += num753[len(N)-i-1][0]+num753[len(N)-i-1][3]
    if check3 and check7:
        ans += num753[len(N)-i-1][1]
    if int(N[i])<7:
        break
    if int(N[i])==7:
        if i==len(N)-1:
            if check5 and check7:
                ans += 1
            if check3 and check7:
                ans += 1
            if check3 and check5:
                ans += 1
        check7 = True
        continue
    ans += num753[len(N)-i-1][3]+num753[len(N)-i-1][6]
    if check3:
        ans += num753[len(N)-i-1][1]+num753[len(N)-i-1][5]
    if check5:
        ans += num753[len(N)-i-1][0]+num753[len(N)-i-1][4]
    if check3 and check5:
        ans += num753[len(N)-i-1][2]
    break

print(ans)

Solution (Python):
def aaa(n):
    if n==1:
        a=[3,5,7]
    else:
        a=[]
        b=aaa(n-1)
        for i in b:
            a.append(i*10+3)
            a.append(i*10+5)
            a.append(i*10+7)
    return a

N=int(input())
n=N
S=0
i=0
while n>0:
    n=n//10
    i+=1
n=i
for j in range(n):
    a=aaa(j+1)
    for i in range(len(a)):
        if a[i]<N+1:
            p=0
            q=0
            r=0
            while a[i]>0:
                if a[i]%10==3:
                    p=1
                if a[i]%10==5:
                    q=1
                if a[i]%10==7:
                    r=1
                a[i]=a[i]//10
            if p*q*r==1:
                S+=1

        
print(S)

Solution (Python):
from itertools import product
n=int(input())
num_list=['7','5','3']
c=0
for j in range(1,10):
    for i in (product(num_list,repeat=j)):
        check=i.count('7')*i.count('3')*i.count('5')
        if int(''.join(i))<=n and check:
            c+=1
print(c)

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

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

count = 0

num = ""

def dfs(num):
    global count
    n = int(num)
    if n <= N:
        if "3" in num and "5" in num and "7" in num:
            count += 1
    else:
        return
    if int(num + "3") <= N:
        tmp1 = dfs(num + "3")
    if int(num + "5") <= N:
        tmp2 = dfs(num + "5")
    if int(num + "7") <= N:
        tmp3 = dfs(num + "7")




dfs(num + "3")
dfs(num + "5")
dfs(num + "7")
print(count)

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

Solution (Python):
def c_755(N):
    from itertools import product
    ans = 0
    for d in range(3, 10):
        
        for s in product('357', repeat=d):
            
            if not all([s.count('3'), s.count('5'), s.count('7')]):
                continue
            v = int(''.join(s))
            if v <= N:
                ans += 1
    return ans

N = int(input())
print(c_755(N))

Solution (Python):
def f(x, y):
	if y == 0:
		return 0
	return [3, 5, 7][x % 3] + f(int(x / 3), y - 1) * 10

N = int(input())
ans = 0
for i in range(3, 10):
	if 10 ** (i - 1) > N:
		break
	for j in range(3 ** i):
		a = f(j, i)
		if a <= N:
			if set(str(a)) == set("357"):
				ans = ans + 1
		else:
			break
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(100000)
ans = 0

def dfs(s, n):
    global ans
    if s == "":
        pass
    elif int(s) > n:
        return
    elif "3" in s and "5" in s and "7" in s:
        
        ans += 1

    for i in "753":
        dfs(s+i, n)


def main():
    global ans
    n = int(input())
    dfs("", n)
    print(ans)

main()

Solution (Python):
N = int(input())
ans = 0
cand = []

def dfs(s) :
    if s != '' and int(s) > N:
        return
    cand.append(s)
    dfs(s+'3')
    dfs(s+'5')
    dfs(s+'7')

dfs('')
for i in cand:
    if '3' in i and '5' in i and '7' in i:
        ans += 1

print(ans)

Solution (Python):
import itertools

N = int(input())
ans = 0

for i in range(3, len(str(N)) + 1):
    cand = list(map(lambda x: "".join(x), itertools.product("357", repeat=i)))
    for c in cand:
        if int(c) > N:
            continue
        elif all(c.count(s) > 0 for s in "357"):
            ans += 1

print(ans)

Solution (Python):
def C3():
    N = int(input())
    def make_list(s):
        S = [s]
        if int(s) <= N:
            S.extend(make_list(s + "3"))
            S.extend(make_list(s + "5"))
            S.extend(make_list(s + "7"))
        return S

    datalist = make_list("0")

    ans = 0
    for i in datalist:
        s = 0
        f = 0
        t = 0
        for j in list(i):
            if j == "7":
                s = 1
            if j == "5":
                f = 1
            if j == "3":
                t = 1
        if s + f + t == 3 and int(i) <= N:
            ans += 1
    print(ans)
C3()

Solution (Python):
def num_357(ls, i, num_l):
    l = ["3", "5", "7"]
    if i > 0:
        for c in l:
            i -= 1
            ls.append(c)
            num_l.append("".join(ls))
            num_357(ls, i, num_l)
            ls.pop(-1)
            i += 1
    else:
        return

num_l = []
ls = []
i =9 

num_357(ls, i, num_l)
num_new = []
for l in num_l:
    if "3" in l and "5" in l and "7" in l:
        num_new.append(int(l))
N = int(input())
import bisect

num_new.sort()
print(bisect.bisect(num_new, N))

Solution (Python):
import itertools


def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)


n = int(input())
size = len(str(n))
l = [3,5,7]
counter = 0
test = []
while size >= 3:
    for i in range(3**size):
        temp = list(Base_10_to_n(i,3))
        for k in range(size-len(temp)):
            temp.insert(0,'0')
        test.append(temp)
    size -= 1

for i in range(len(test)):
    val = 0
    three = 0
    five = 0
    seven = 0
    for k in range(len(test[i])):
        val += l[int(test[i][k])] * 10**(len(test[i])-k-1)
        if l[int(test[i][k])] == 3:
            three += 1
        elif l[int(test[i][k])] == 5:
            five += 1
        elif l[int(test[i][k])] == 7:
            seven += 1
    if three > 0 and five > 0 and seven > 0 and val <= n:
        counter += 1

print(counter)

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())

s357 = list("357") + [""]
cnt = []
for v in itertools.product(s357, repeat=9):
    s = "".join(v)
    if s and len(set(list(s))) >= 3 and int(s) <= n:
        cnt.append(int(s))
print(len(set(cnt)))

Solution (Python):
import sys
import itertools
n=input()
n2=int(n)
num=['3','5','7']
cnt=0
if n2<357:
    print(0)
    sys.exit()
for i in range(3,len(n)+2):
    for j in itertools.product(num,repeat=i):
        if len(set(j))==3 and int("".join(j))<=n2:
            cnt+=1
print(cnt)

Solution (Python):
from itertools import product
a=['7','5','3']
n=int(input())
c=0
for j in range(1,10):
    for i in (product(a,repeat=j)):
        check=i.count('7')*i.count('3')*i.count('5')
        if int(''.join(i))<=n and check:c+=1
print(c)

Solution (Python):
n=int(input())
a=[['7', '5', '3']]*9
for i in range(8):
    for j in range(len(a[i])):
        a[i+1].append(a[i][j]+'7')
        a[i + 1].append(a[i][j] + '5')
        a[i + 1].append(a[i][j] + '3')
ans=[]
for num in a[0]:
    if int(num) <= n and num.count('3')>0 and num.count('5') >0 and num.count('7')>0 :
        ans.append(num)
print(len(set(ans)))

Solution (Python):
n=int(input())
a=[['7', '5', '3']]*9
for i in range(8):
    for j in range(len(a[i])):
        a[i+1].append(a[i][j]+'7')
        a[i + 1].append(a[i][j] + '5')
        a[i + 1].append(a[i][j] + '3')
ans=[]
for num in a[0]:
    if int(num) <= n and num.count('3')>0 and num.count('5') >0 and num.count('7')>0 :
        ans.append(num)
print(len(set(ans)))

Solution (Python):
def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(i) > 0 for i in '357') else 0

    for i in '357':
        ret += dfs(s + i)
    return ret


n = int(input())

print(dfs('0'))

Solution (Python):
N = int(input())
ans = set(["3","5","7"])
list = ["3","5","7"]
x_list = ["3","5","7"]
cnt = 0
f = 0
i = 0

while f == 0:
    for j in range(3):
        num = x_list[i] + list[j]
        if int(num) > N:
            f = 1
            break
        x_list.append(num) 
    i += 1

for i in x_list:
    ans_list = [i for i in str(i)]
    s = set(ans_list)
    if s == ans:
        cnt += 1

print(cnt)

Solution (Python):



import sys


sys.setrecursionlimit(10 ** 6)

read_single_int = lambda: int(sys.stdin.readline().strip())


def dfs(s: str, n: int, count: list):
    if int(s) > n:
        return
    if s.count('3') >= 1 and s.count('5') >= 1 and s.count('7') >= 1:
        count[0] += 1
    
    dfs(s+'3', n, count)
    dfs(s+'5', n, count)
    dfs(s+'7', n, count)


def solution(n: int):
    count = [0]
    dfs('0', n, count)
    return count[0]


def main():
    n = read_single_int()
    print(solution(n))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
divAble = [0 for i in range(len(str(n)))]
digit = len(str(n))
count = 0


def search(nowDigit, num, maxDigit, okList):
    if nowDigit < maxDigit:
        search(nowDigit + 1, num * 10 + 3, maxDigit, [1, okList[1], okList[2]])
        search(nowDigit + 1, num * 10 + 5, maxDigit, [okList[0], 1, okList[2]])
        search(nowDigit + 1, num * 10 + 7, maxDigit, [okList[0], okList[1], 1])
    else:
        if num <= n:
            
            global count
            if sum(okList) == 3:
                count += 1
for i in range(digit+1):
    search(0, 0, i, [0, 0, 0])
print(count)
"""



if int(str(n)[0]) >= 7:
    divAble[0] += 1
elif n > 10:
        divAble[1] += 1

if int(str(n)[0]) >= 5:
    divAble[0] += 1
elif n > 10:
        divAble[1] += 1

if int(str(n)[0]) >= 3:
    divAble[0] += 1
elif n > 10:
        divAble[1] += 1

for i in range(1, len(divAble)):
    divAble[i] += divAble[i-1]

print(divAble)
if sum(divAble) == 0:
    print(0)
    exit()
count = 1
for i in range(len(divAble)):
    if divAble[i] > 0:
        count *= divAble[i]
print(count)
"""

Solution (Python):
def func(S, num):
    if len(S) == 10:
        return 0
    ret = 0
    if '3' in S and '5' in S and '7' in S and int(S) <= num:
        ret += 1
    ret += func(S + '3', num)
    ret += func(S + '5', num)
    ret += func(S + '7', num)
    return ret

print func('', input())

Solution (Python):
def func(S, num):
    ret = 0
    if '3' in S and '5' in S and '7' in S and int(S) <= num:
        ret += 1
    if len(S) == 10:
        return 0
    ret += func(S + '3', num)
    ret += func(S + '5', num)
    ret += func(S + '7', num)
    return ret

print func('', input())