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

answer=0
def dfs(d):
  global answer
  if d>N:
    return
  
  d_str=str(d)
  if "3" in d_str and "5" in d_str and "7" in d_str:
    
    answer+=1
  
  for dd in [3,5,7]:
    dfs(10*d+dd)
    
dfs(0)
print(answer)

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):
def rec(s):
    if not (s == "") and int(s) > n:
        return 0
    res = 0
    if all(c in s for c in '753'):
        res += 1
    for c in '753':
        res += rec(s + c)
    return res

n = int(input())
print(rec(""))

Solution (Python):
import itertools
s = input()
cnt = 0

digits = len(s)

cntl = [0, 6, 42, 192, 732, 2538, 8334]

number = ["3", "5", "7"]
if digits < 3:
    print(0)
    exit()
for i in itertools.product(number, repeat=digits):
    if "3" in i and "5" in i and "7" in i:
        if int(''.join(i)) <= int(s):
            cnt += 1
print(cnt + cntl[digits - 3])

Solution (Python):



import itertools
import bisect

n = int(input())
l = len(str(n))
ans = []
for i in range(3,l+1):
    for x in itertools.product("357",repeat = i):
        s = ''
        if x.count('7')*x.count('5')*x.count('3') == 0:
            continue
        for j in x:
            s += j
        ans.append(int(s))
ans.sort()
print(bisect.bisect_right(ans,n))

Solution (Python):



n = int(input())

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

print(dfs('0'))

Solution (Python):
n=int(input())
l=[]
import itertools
for i in range(3,10):
    for x in itertools.product("357",repeat=i):
        p=""
        if x.count("7")*x.count("5")*x.count("3")==0:
            continue
        for j in x:
            p+=j
        l.append(int(p))
l.sort()

import bisect
ans=bisect.bisect_right(l,n) 
print(ans)

Solution (Python):
def rec(s):
    """引数末尾に753を付け加えてできる753数
    753以外の数が現れないように文字を加えているので、
    ・すべて一回以上出たら753数に加算
    ・Nを超えたらreturn 0
    させればよい"""
    
    if int(s) > n:
        return 0

    res = 0
    if all(c in s for c in '753'):
        res += 1

    
    for c in '753':
        res += rec(s + c)
    return res


n = int(input())
print(rec('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())

d=['3','5','7','']
k=10
a=d
def make(k,l):
    if k==0:
        return l
    t=set()
    for i in l:
        for j in d:
            t.add(i+j)
    return make(k-1,t)

s=[]    
for i in make(k,d):
    if i!='':
        u=set()
        for j in i:
            u.add(j)
        if len(u)==3:
            s.append(int(i))

ans=sum([1 if x<=n else 0 for x in s])
print(ans)

Solution (Python):


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

Solution (Python):


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

Solution (Python):


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

Solution (Python):


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

Solution (Python):
from collections import deque
N = int(input())
memo = {i:1 for i in [357, 375, 537, 573, 735, 753]}
ans = 0
queue = deque()
mod = [10**i for i in range(10)]
for key in memo.keys():
  if key <= N:
    ans += 1
    queue.append(key)
while queue:
    key = queue.popleft()
    len_key = len(str(key))
    for i in range(len_key):
        for j in [3,5,7]:
            tmp = (key // mod[i]) * mod[i+1] + j * mod[i] + key % mod[i]
            if tmp not in memo and tmp <= N:
                ans += 1
                memo[tmp] = 1
                queue.append(tmp)
print(ans)

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

Solution (Python):
import itertools

a = input()
b = ["3", "5", "7"]
d = 0
for i in range(1, len(a)+1):
    for j in itertools.product(b, repeat=i):
        c = ""
        for k in range(len(j)):
            c += j[k]
        if int(c) <= int(a):
            if "3" in c and "5" in c and "7" in c:
                d += 1
print(d)

Solution (Python):
from functools import lru_cache
n = int(input())

def variety(n, arr) :
    ms = set()
    for a in range(n) :
        ms |= count(a+1, arr)
    return(ms)

@lru_cache(maxsize=36)
def count(n, arr) :
    if n == 1 :
        return set(arr)
    else :
        ms = set()
        for a in arr :
            for m in count(n-1, arr) :
                m2 = int(str(a)+str(m))
                ms.add(m2)
        return ms

mylist = list(variety(9, (7, 5, 3))\
            - variety(9, (7, 5))\
            - variety(9, (5, 3))\
            - variety(9, (3, 7)))

print(len([1 for i in mylist if i <= n]))

Solution (Python):
N=input()

if len(N)<3:
    print(0)
else:
    arr=set([357, 375, 537, 573, 735, 753])
    for i in range(len(N)-3):
        new=set()
        for num in arr:
            for j in range(len(str(num))+1):
                n=str(num)[:j]+'3'+str(num)[j:]
                new.add(int(n))
                n=str(num)[:j]+'5'+str(num)[j:]
                new.add(int(n))
                n=str(num)[:j]+'7'+str(num)[j:]
                new.add(int(n))
        arr |= new

    arr=list(arr)
    arr.sort()
    cnt=0
    for i in range(len(arr)):
        if arr[i]<=int(N):
            cnt+=1
        else:
            break
    print(cnt)

Solution (Python):
"""
753の数
"""

import sys
sys.setrecursionlimit(100000)
N = int(input())

"""
1. Gを予め作って探索するパターン
2. Gを作りながら探索するパターン
"""
cnt = 0
def dfs(v):
    global cnt
    
    
    num = "753"
    
    for n in num:
        next_v = v + n
        
        
        if int(next_v) > N: continue
        
        dfs(next_v)
        if "3" in next_v and "5" in next_v and "7" in next_v:
            cnt += 1

dfs("")
print(cnt)

Solution (Python):
def make_num(n):
    if int(n) > N:
        return 0
    elif "3" in n and "5" in n and "7" in n:
        ans = 1
    else:
        ans = 0
    for i in "357":
        ans += make_num(n+i)
    return ans
N = int(input())
print(make_num("0"))

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

def dfs(s):
    if int(s) > N:
        return 0
    ok = True
    ret = 0
    for c in "753":
        if s.count(c) < 1:
            ok = False
            break
    if ok:
        ret = 1
    for c in "753":
        ret += dfs(s+c)
    return ret

print(dfs("0"))

Solution (Python):

N = int(input())
ans = 0

def count(s):
    global ans
    if int(s) > N:
        return 0
    elif s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
        ans += 1

    for j in "357":
        count(s+j)


count("0")
print(ans)

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

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
nums = ''

def dfs(nums):
    global cnt
    
    if len(nums) >= 10:
        return
        
    k = list(nums)
    k = set(nums)

    if len(nums) >= 1:
        if int(nums) <= N and len(k) >= 3:
            cnt += 1
    
    dfs(nums + '3')
    dfs(nums + '5')
    dfs(nums + '7')

    return

dfs(nums)

print(cnt)

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

cnt = 0
nums = ''

def dfs(nums):
    global cnt
    
    if len(nums) >= 10:
        return
        
    k = list(nums)
    k = set(nums)

    if len(nums) >= 1:
        if int(nums) <= N and len(k) >= 3:
            cnt += 1
    
    dfs(nums + '3')
    dfs(nums + '5')
    dfs(nums + '7')

    return

dfs(nums)

print(cnt)

Solution (Python):
def dfs(s,num):
    if int(s)>num:
        return 0
    if s.count('7')>0 and s.count('5')>0 and s.count('3')>0:
        ret=1
    else:
        ret=0
    for i in "753":
        ret+=dfs(s+i,num)
    return ret
n=int(input())
print(dfs('0',n))

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


c = 0
num = 0
def check(n):
	strn = str(n)
	l = [0, 0, 0]
	for c in strn:
		if c == '3':
			l[0] = 1
		elif c == '5':
			l[1] = 1
		elif c == '7':
			l[2] = 1
	return all(l) or False

def gen(n):
	global c
	
	if n > num:
		return
	if check(n):
		
		c += 1
	for i in [3, 5, 7]:
		k = 10 * n + i
		gen(k)

def main():
	global num
	num = int(input().strip())
	gen(0)
	print(c)

if __name__ == '__main__':
	main()

Solution (Python):
N = input()
 
ans = 0
def dfs(m):
    global ans
    if len(set(m))==3 and int(m)<=int(N):
        ans+=1
        
    if len(m)<len(N):
        for i in "357":
            dfs(m+i)
dfs("")
print(ans)

Solution (Python):


import itertools

a = input()
N = int(a)
e = len(a)
c = 0
for i in range(3, e):
    o = itertools.product(['3', '5', '7'], repeat=i)
    for j in o:
        if all(j.count(k) > 0 for k in '357') == True:
            c += 1
l = itertools.product(['3', '5', '7'], repeat=e)
for m in l:
    if all(m.count(k) > 0 for k in '357') == True and int(''.join(m)) <= N:
        c += 1
print(c)

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

def is_753(n):
	s = str(n)
	f = [0,0,0]
	for c in s:
		if c == '3':
			f[0] = 1
		elif c == '5':
			f[1] = 1
		elif c == '7':
			f[2] = 1
	if all(f):
		return True
	else:
		return False

N = 0
c = 0
def gen(n):
	global c
	for i in [3,5,7]:
		k = 10 * n + i
		
		if k > N:
			return
		if is_753(k):
			c += 1
			
		gen(k)

def main():
	global N
	s = input().strip()
	N = int(s)
	n = len(s)

	gen(0)
	print(c)


if __name__ == '__main__':
	main()

Solution (Python):
N = input()

ans = 0
def dfs(m):
    global ans
    if len(set(m)) == 3 and int(m) <= int(N):
        
        ans += 1

    if len(m) < len(N):
        for c in "357":
            dfs(m+c)

dfs("")
print(ans)

Solution (Python):
n = input()
count357 = ["3", "5", "7"]
i = 0
while int(count357[-1]) <= int(n):
    for j in range(3):
        count357.append(str(int(count357[i])*10 + int(count357[j])))
        if int(count357[-1]) > int(n):
            break
    i += 1
count357.pop(-1)
count = 0
for i in range(len(count357)):
    count += 1 if "3" in count357[i] and "5" in count357[i] and "7" in count357[i] else 0

print(count)

Solution (Python):
n = input()
a = "357"
count357 = ["3", "5", "7"]
i = 0
while int(count357[-1]) <= int(n):
    for j in range(3):
        count357.append(str(int(count357[i])*10 + int(count357[j])))
        if int(count357[-1]) > int(n):
            break
    i += 1
count357.pop(-1)
count = 0
for i in range(len(count357)):
    count += 1 if "3" in count357[i] and "5" in count357[i] and "7" in count357[i] else 0

print(count)

Solution (Python):
n = input()
a = "357"
count357 = ["3", "5", "7"]
i = 0
count = 0
while int(count357[-1]) <= int(n):
    for j in range(3):
        count357.append(str(int(count357[i])*10 + int(count357[j])))
        if int(count357[-1]) > int(n):
            break
    i += 1
count357.pop(-1)
for i in range(len(count357)):
    if "3" in count357[i] and "5" in count357[i] and "7" in count357[i]:
        count += 1
print(count)

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

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

def f(x):
    if int(x) > n:
        return 0
    if all([x.count(a) > 0 for a in '753']):
        num = 1
    else:
        num = 0
    for a in '753':
        num += f(x + a)
    return num

print(f('0'))

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

q = deque([""])
q_is3 = deque([0])
q_is5 = deque([0])
q_is7 = deque([0])
N = "357"
ans = 0
while q:
    num = q.popleft()
    is3 = q_is3.popleft()
    is5 = q_is5.popleft()
    is7 = q_is7.popleft()
    for n in N:
        next_v = num + n
        if int(next_v) > X: continue
        else:
            next_is3 = is3 or n == "3"
            next_is5 = is5 or n == "5"
            next_is7 = is7 or n == "7"
            q.append(next_v)
            q_is3.append(next_is3)
            q_is5.append(next_is5)
            q_is7.append(next_is7)
            if next_is3 and next_is5 and next_is7:
                ans += 1
print(ans)

Solution (Python):
from collections import deque
X = int(input())
q = deque([""])
N = "357"
ans = 0
while q:
    num = q.popleft()
    for n in N:
        next_v = num + n
        if int(next_v) > X: continue
        else:
            q.append(next_v)
            if "3" in next_v and "5" in next_v and "7" in next_v:
                ans += 1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(100000)

cnt = 0
num = ""
X = int(input())
def dfs(num,is3,is5,is7):
    global cnt
    if is3 and is5 and is7:
        cnt += 1 
    N = "357"
    for n in N:
        next_v = num + n
        if int(num+n) > X: continue 
        
        dfs(next_v,is3 or n=="3",is5 or n=="5",is7 or n=="7")

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

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


def f755(d, n, t, f, s):
    if NI < n:
        return 0
    if d < 0 and (t and f and s):
        return 1
    r = 0
    if n == 0 and d > 0:
        r += f755(d - 1, n, t, f, s)
    if d >= 0:
        r += f755(d - 1, n + 3 * (10 ** d), t or 1, f, s)
        r += f755(d - 1, n + 5 * (10 ** d), t, f or 1, s)
        r += f755(d - 1, n + 7 * (10 ** d), t, f, s or 1)
    return r


ans = f755(len(N) - 1, 0, 0, 0, 0)
print(ans)

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

def cnt753(s):
  if int(s) > N:
    return 0
  if all(s.count(c) > 0 for c in ["7","5","3"]):
    ret = 1
  else:
    ret = 0
  for c in ["7","5","3"]:
    ret += cnt753(s+c)
  return ret
print(cnt753("0"))

Solution (Python):
import sys
sys.setrecursionlimit(10**5)
N = int(input())

def rec(num, use):
    if num > N:
        return 0

    i = 0
    if (use == 0b111):
        i = 1

    return rec(num*10+7, use | 0b100)\
         + rec(num*10+5, use | 0b010)\
         + rec(num*10+3, use | 0b001)\
         + i

print(rec(0,0))

Solution (Python):
"""
dfsでとき直し114
7,5,3がそれぞれ1回以上現れる

3-3-3
   -5
   -7
 -5-3
   -5
   -7
 -7-3
   -5
   -7
とかそういうヤツ

3 33 35 37 5 
"""

import sys
sys.setrecursionlimit(100000)

cnt = 0
num = "0"
X = int(input())
def dfs(num,is3,is5,is7):
    
    global cnt
    if is3 and is5 and is7:
        cnt += 1 
    N = "357"
    for n in N:
        if int(num+n) > X: continue 
        if n == "3":
            dfs(num+n,True,is5,is7)
        elif n == "5":
            dfs(num+n,is3,True,is7)
        elif n == "7":
            dfs(num+n,is3,is5,True)


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

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())


def dfs(x):
    ret = 0
    if int(x) > N:
        return ret
    if '7' in x and '5' in x and '3' in x:
        ret += 1
    for k in '753':
        ret += dfs(x + k)
    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):

import sys

def dfs(s :str, n: int):
    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, n)
    return ret


def solve(N: int):
    print(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))  
    solve(N)

if __name__ == '__main__':
    main()

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

def dfs(x, f3, f5, f7):
  cnt = 0
  if x>n:
    return 0
  if f3>0 and f5>0 and f7>0:
    cnt += 1

  t1 = x*10+3
  t2 = x*10+5
  t3 = x*10+7
  cnt += dfs(t1, f3+1, f5, f7)
  cnt += dfs(t2, f3, f5+1, f7)
  cnt += dfs(t3, f3, f5, f7+1)
  return cnt

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

Solution (Python):
N = input()

import itertools

num = int(N)
d = len(N)

lst = ['3', '5', '7']

arr = []
for j in range(3, d+1):
    arr += [int("".join(i)) for i in itertools.product(lst, repeat=j) if '3' in i and '5' in i and '7' in i]

cnt = sum([arr[k]<=num for k in range(len(arr))])
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())
i=1
j=0
k=0
s=["3","5","7"]
d=["3","5","7"]
g=[]
k2=0
while i!=10:
    f=len(d)
    while j!=3:
        k = k2
        while k!=f:
            d.append(d[k]+s[j])
            k+=1


        j+=1
    k2 = f
    j=0
    i+=1
i=0
while i!=len(d):
    if ("3" in d[i])==True and ("5" in d[i])==True and ("7" in d[i])==True:
        i+=1
    else:
        del d[i]

d=list(map(int,d))
d.sort()
ans=0
i=0
x=d[i]
while x<=n:
    ans+=1
    i+=1
    x=d[i]


print(ans)

Solution (Python):
n = int(input())
import itertools
keta = len(str(n))
l = []
for i in range(3,keta + 1):
    l = l + list(itertools.product([7,5,3], repeat = i))
l = list(l)
l = map(lambda x: "".join(list(map(str, x))), l)
l = map(int, l)
l = list(l)
l = filter(lambda x: x <= n, l)
l = filter(lambda x: str(x).find("3") != -1, l)
l = filter(lambda x: str(x).find("5") != -1, l)
l = filter(lambda x: str(x).find("7") != -1, l)
l = list(l)
print(len(l))

Solution (Python):
N = int(input())
n = len(str(N))
s = ['3', '5', '7']
ans = 0
for d in range(3, n+1):
    for i in range(3 ** d):
        x = ''
        for j in range(d):
            x += s[(i//(3**j))%3]
        if '3' in x and '5' in x and '7' in x and int(x) <= N:
            ans += 1
print(ans)

Solution (Python):
N = int(input())
n = len(str(N))
s = ['3', '5', '7']
ans = 0
for d in range(3, n+1):
    for i in range(3 ** d):
        x = ''
        for j in range(d):
            x += s[(i//(3**j))%3]
        if '3' in x and '5' in x and '7' in x and int(x) <= N:
            ans += 1
print(ans)

Solution (Python):
n = input()
l = len(n)
ls = [4**int(x) for x in range(l)]
ls.sort(reverse=True)

cnt = 0
for i in range(4**l):
    can = []
    for j in range(l):
        if i//ls[j]==3:
            can.append("7")
            i = int(i-ls[j]*3)
        elif i//ls[j]==2:
            can.append("5")
            i = int(i-ls[j]*2)
        elif i//ls[j]==1:
            can.append("3")
            i = int(i-ls[j])
        else:
            can.append("0")
    can = int("".join(can))
    can = list(str(can))
    if len(set(can)&{"0"})==0 and len({"3","5","7"}-set(can))==0:
        pass
    else:
        continue
    can = int("".join(can))
    if int(n)>=can:
        cnt+=1
    else:
        pass

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 = input()
key = ["3", "5", "7"]
cnt = 0
for k in range(3, len(n)+1):
    for i in range(3**k):
        t = []
        s = ""
        m = i
        for j in range(k):
            s += key[m%3]
            m = m//3
        if int(s) <= int(n) and len(set(list(s))) == 3:
            cnt += 1
print(cnt)

Solution (Python):
import itertools
def sgs(k):
    return 3**k-3*(2**k-2)-3

n = int(input())
l = len(str(n))
if l <= 2:
    print(0)
    exit()
origin_list = ["3","5","7"]
lst=list(itertools.product(origin_list,repeat=l))
lst_753 = [i for i in lst if "3" in i and "5" in i and "7" in i]
lst_new = [int(''.join(i)) for i in lst_753]
sum_sgs = sum([sgs(i) for i in range(3,l)])

n_k = sum(i <= n for i in lst_new)

ans = sum_sgs+n_k
print(ans)

Solution (Python):
N=int(input())
ans=0
def dfs(s):
	global ans
	if N<int(s):
		return 0
	if all([s.count(i) for i in "753"]):
		ans+=1
	for i in "753":
		dfs(s+i)
dfs("0")
print(ans)

Solution (Python):
N=int(input())
def next_357(num_arr,i=-1):
    if len(num_arr) < -i:
        num_arr.insert(0,3)
        return num_arr
    if num_arr[i] == 3:
        num_arr[i] = 5
        return num_arr
    elif num_arr[i] == 5:
        num_arr[i] = 7
        return num_arr
    elif num_arr[i] == 7:
        num_arr[i] = 3
        i -= 1
        return next_357(num_arr,i)
ans = 1
a357 = [3,5,7]
while True:
    if N < 357:
        ans = 0
        break
    elif N == 357:
        break
    else:
        a357 = next_357(a357)
        if int("".join(map(str, a357))) <= N:
            if a357.count(3) >= 1 and a357.count(5) >= 1 and a357.count(7) >= 1:
                ans += 1
        else:
            break
print(ans)

Solution (Python):

n = int(input())

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

def dfs(start):
    if int(start) > n:
        return 0
    if not ("3" in start and "5" in start and "7" in start):
        count=0
    else:
        count=1
    count += dfs(start + "3")
    count += dfs(start + "5")
    count += dfs(start + "7")
    return count
print(dfs("3")+dfs("5")+dfs("7"))

Solution (Python):
import sys
sys.setrecursionlimit(200000)
n = int(input())

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

def dfs(start):
    if int(start) > n:
        return 0
    if not ("3" in start and "5" in start and "7" in start):
        count=0
    else:
        count=1
    count += dfs(start + "3")
    count += dfs(start + "5")
    count += dfs(start + "7")
    return count
print(dfs("3")+dfs("5")+dfs("7"))

Solution (Python):
import itertools

N=input()

ans=0
for i in range(3,len(N)+1):
    for j in itertools.product('357', repeat=i):
        s=''.join(j)
        if int(s)<=int(N) and s.count('3')>=1 and s.count('5')>=1 and s.count('7')>=1:
            ans+=1

print(ans)

Solution (Python):
N = input()

d = len(N)

T = [0, 3, 5, 7]
A = []
for i in range(4**d):
    for j in range(d):
        n = i
        c = 0
        a = 0
        for k in range(j + 1):
            a += T[n % 4] * 10**c
            n //= 4
            c += 1
    A.append(a)

def is753(n):
    if n == 0:
        return False
    n_str = str(n)
    has3 = False
    has5 = False
    has7 = False
    for s in n_str:
        if s == '0':
            return False
        elif s == '3':
            has3 = True
        elif s == '5':
            has5 = True
        elif s == '7':
            has7 = True
    return has3 and has5 and has7

ans = []
ans = [x for x in A if x <= int(N) and is753(x)]


print(len(ans))

Solution (Python):
import itertools

N = int(input())

se = set([0])
for _ in range(10):
  se |= set(10*x+y for x,y in itertools.product(se,[7,5,3]))
  
se = set(str(x) for x in se if 1 <= x <= N)
se = set(x for x in se if set(x) == set('753'))
answer = len(se)
print(answer)

Solution (Python):
S = input()

def solve(s):
	if s and int(s) > int(S):
		return 0
	count = 0
	if set(s) == set("753"):
		
		count = 1
	for c in "753":
		count += solve(s + c)
	return count

print(solve(""))

Solution (Python):
S = input()

def solve(s, n=0, tight=True, value=""):
	if n == len(s):
		while value and value[0] == "0":
			value = value[1:]
		if set("753") == set(value):
			
			return 1
		return 0
	hi = int(s[n]) if tight else 9
	c = 0
	for i in range(hi + 1):
		if i in [7, 5, 3, 0]:
			c += solve(s, n + 1, tight and not(i < hi), value + str(i))
	return c

print(solve(S))

Solution (Python):
N = int(input())
M = len(str(N))
res = [0]
def dfs(x):
    
    if len(x) > M:
        return
    if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0 and int(x) <= N:
        res[0] += 1
    dfs(x + '3')
    dfs(x + '5')
    dfs(x + '7')
    return

dfs('3')
dfs('5')
dfs('7')
print(res[0])

Solution (Python):
N = int(input())
M = len(str(N))

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

res = 0
for m in range(3,M+1):
    for i in range(3 ** m):
        tri = nsin(i, 3).zfill(m)
        nl = []
        if tri.count('0') > 0 and tri.count('1') > 0 and tri.count('2') > 0:
            for j in range(m):
                if tri[j] == '0':
                    nl.append('3')
                elif tri[j] == '1':
                    nl.append('5')
                else:
                    nl.append('7')
            x = ''.join(nl)
            if int(x) <= N:
                res += 1

print(res)

Solution (Python):
N = int(input())
M = len(str(N))

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

res = 0
for m in range(3,M+1):
    for i in range(3 ** m):
        tri = nsin(i, 3).zfill(m)
        nl = []
        if tri.count('0') > 0 and tri.count('1') > 0 and tri.count('2') > 0:
            for j in range(m):
                if tri[j] == '0':
                    nl.append('3')
                elif tri[j] == '1':
                    nl.append('5')
                else:
                    nl.append('7')
            x = ''.join(nl)
            if int(x) <= N:
                res += 1

print(res)

Solution (Python):
n=int(input())
def dfs(m):
  if m>n:return 0
  a=all(str(m).count(i)>0for i in"753")+0
  for i in [7,5,3]:a+=dfs(m*10+i)
  return a
print(dfs(0))

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

def saiki(i,ans):
    if i>N:
        return ans
    else:
        s = str(i)
        if ("7" in s) and ("5" in s) and ("3" in s):
            ans += 1
        ans = saiki(i*10+3,ans)
        ans = saiki(i*10+5,ans)
        ans = saiki(i*10+7,ans)
        return ans
    
print(saiki(0,0))

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

num_len = len(str(N))

lis = []

def dfs(cur, number, count):
    if '3' in number and '5' in number and '7' in number:
        if int(number) <= N:
            lis.append(number)
    if num_len == cur:
        return

    ret1 = dfs(cur + 1, number + '3', count)
    ret2 = dfs(cur + 1, number + '5', count)
    ret3 = dfs(cur + 1, number + '7', count)
    
    return lis


print(len(dfs(0, '', count=0)))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()


def ten2n(a,n):
  x=a//n
  y=a%n
  if x:
    return ten2n(x,n)+str(y)
  return str(y)

def main():
  n=I()

  l=[]
  for i in range(pow(4,9)):
    l.append(ten2n(i,4).replace('3','7').replace('2','5').replace('1','3'))

  cnt=0
  for x in l:
    if int(x)<=n:
      if '3' in x and '5' in x and '7' in x and '0' not in x:
        cnt+=1
    else:
      break

  return cnt

print(main())

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

def dfs(s):

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

print(dfs('0'))

Solution (Python):
import itertools
n = input()
dp = [[[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)]for l in range(len(n))]


for i in range(len(n)):
    dp[i][0][0][0][0] = 1

for j in range(10):
    if int(n[0]) >= j and j in [3, 5, 7]:
        dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1

for i, j, k, l, m in itertools.product(range(len(n)-1), range(2), range(2), range(2), range(10)):
    if m in [3, 5, 7]:
        dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l]
        if m <= int(n[i+1]):
            dp[i + 1][m == int(n[i+1])][j or m == 3][k or m == 5][l or m == 7] += dp[i][1][j][k][l]

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

Solution (Python):
import itertools
n = input()
dp = [[[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)]for l in range(len(n))]


for i in range(len(n)):
    dp[i][0][0][0][0] = 1

for j in range(10):
    if int(n[0]) >= j:
        dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1
dp[0][1][0][0][0] = 0

for i, j, k, l, m in itertools.product(range(len(n)-1), range(2), range(2), range(2), range(10)):
    if m in [3, 5, 7]:
        dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l]
        if m <= int(n[i+1]):
            dp[i + 1][m == int(n[i+1])][j or m == 3][k or m == 5][l or m == 7] += dp[i][1][j][k][l]

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