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):
A = [3, 5, 7]
B = [3, 5, 7]
for i in range(9):
    C = []
    for b in B:
        C.append(10*b+3)
        C.append(10*b+5)
        C.append(10*b+7)
    A += C
    B = C
n = int(input())
c = 0
for a in A:
    if a > n:
        break
    if set(list(str(a))) == {'3', '5', '7'}:
        c += 1
print(c)

Solution (Python):
def resolve():
    from collections import deque
    n = int(input())
    ans = 0
    num = deque([3,5,7])
    while num[0] <= n:
        test = num.popleft()
        num.append(test * 10 + 3)
        num.append(test * 10 + 5)
        num.append(test * 10 + 7)
        if list(set([int(x) for x in list(str(test))])) == [3,5,7]:
            ans += 1
    print(ans)

resolve()

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

ans = []
def dfs(x):
    if '3' in x and '5' in x and '7' in x and int(x) <= n:ans.append(x)
    if len(x) > 0 and int(x) > n:return
    dfs(x+'3')
    dfs(x+'5')
    dfs(x+'7')
        

    
    
    
    
    
dfs('')
print(len(ans))

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

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

def is_valid(x):
    three = False
    five = False
    seven = False
    for i in str(x):
        if i == "3":
            three = True
        elif i == "5":
            five = True
        elif i == "7":
            seven = True
    if three and five and seven:
        return True
    else:
        return False

while stack:
    x = stack.pop()
    if is_valid(x):
        count += 1
    for next in (3, 5, 7):
        xx = x * 10 + next
        if xx <= N:
            stack.append(xx)
print(count)

Solution (Python):
N=int(input())
num=["3","5","7"]

que=["3","5","7"]
count=0
for i in range(10**9):
  p=que.pop(0)
  for s in num:
    now=p+s
    
    if int(now)>N:
      print(count)
      exit()
    que.append(now)
    if len(set(now))==3:
      count+=1

Solution (Python):
import itertools

n=input()
p=[]
for i in range(3,len(n)+1):
    p+=list(itertools.product("357",repeat=i))
ans=0
for i in range(len(p)):
    s="".join(p[i])
    if int(s)>int(n):
        continue
    if all(s.count(c) for c in "753"):
        ans+=1
print(ans)

Solution (Python):
n = int(input())
point = 0
def sitigosan(num,keta):
    global point
    now = keta+num
    if int(now) > n:
        return
    else:
        if "3" in now and "5" in now and "7" in now:
            point += 1
        return sitigosan("3",str(now)),sitigosan("5",str(now)),sitigosan("7",str(now))
sitigosan("","3")
sitigosan("","5")
sitigosan("","7")

print(point)

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

def dfs(now):
    if int(now)>n:
        return 0
    for i in "753":
        if i not in now:
            ret=0
            break
    else:
        ret=1
    for i in "753":
        ret+=dfs(now+i)
    return ret
print(dfs("0"))

Solution (Python):
def generate(x):
    for i in [3, 5, 7]:
        yield x * 10 + i

n = int(input())
nums = [3, 5, 7]
ans = 0
num = 0
p = 0
while num < n:
    for res in generate(nums[p]):
        nums.append(res)
        num = res
        if res <= n and set(list(str(res))) == set(list(str(357))):
            ans += 1
    p += 1

print(ans)

Solution (Python):
from collections import deque

N = int(input())
ans = 0
q = deque([7, 5, 3])

while q:
    s = q.pop()
    str_s = str(s)
    ok = True
    ok &= "7" in str_s
    ok &= "5" in str_s
    ok &= "3" in str_s
    ok &= s <= N
    if ok:
        ans += 1
    if len(str_s) < 9:
        q.append(10*s + 3)
        q.append(10*s + 5)
        q.append(10*s + 7)

print(ans)

Solution (Python):
N = int(input())
ans = 0
import itertools
for i in range(1,10):
    for ptn in itertools.product('753',repeat=i):
        s = ''.join(ptn)
        if int(s) > N: continue
        if '3' not in s: continue
        if '5' not in s: continue
        if '7' not in s: continue
        ans += 1
print(ans)

Solution (Python):
from itertools import product

n = int(input())

res = 0
for pattern in product(["0", "3", "5", "7"], repeat=len(str(n))):
    p = int("".join(pattern))
    if "0" not in str(p):
        if p <= n:
            for i in ["3", "5", "7"]:
                if i not in str(p):
                    break
            else:
                res += 1
print(res)

Solution (Python):
def dfs(s):
  res=0
  if s!="":
    if int(s)>n:
      return res
  if (s.count('7')>=1 and s.count('5')>=1 and s.count('3')>=1):res=1
  for c in "357":
    res+=dfs(s+c)
  return res

n=int(input())
print(dfs(''))

Solution (Python):
def examA():
    N, M = LI()
    l = 1; r = N
    for _ in range(M):
        L, R = LI()
        l = max(L,l)
        r = min(R,r)
    ans = max(0,r-l+1)
    print(ans)
    return

def examB():
    N = I()
    S = [I()for _ in range(N)]
    rest = []
    for s in S:
        if s%10==0:
            continue
        rest.append(s)
    if sum(S)%10==0:
        if not rest:
            print(0)
            return
        ans = sum(S) - min(rest)
    else:
        ans = sum(S)
    print(ans)
    return

def examC():
    N, K = LI()
    K -= 1
    A = LI()
    L = A.index(1)
    
    ans = (N-1+K-1)//K
    print(ans)
    return

def examD():
    def ketadp(a):
        n = len(a)
        dp = defaultdict(int)
        dp[0, 0, 0, 0, 0] = 1
        for i, less, has3, has5, has7 in itertools.product(range(n), (0, 1), (0, 1), (0,1), (0,1)):
            max_d = 7 if less else int(a[i])
            for d in range(max_d + 1):
                if d==0 and has3==0 and has5==0 and has7==0:
                    dp[i + 1, 1, has3, has5, has7] += dp[i, less, has3, has5, has7]
                if not (d==3 or d==5 or d==7):
                    continue
                less_ = less or d < max_d
                has3_ = has3 or d == 3
                has5_ = has5 or d == 5
                has7_ = has7 or d == 7
                dp[i + 1, less_, has3_, has5_, has7_] += dp[i, less, has3, has5, has7]

        ans = sum(dp[n, less, 1, 1, 1] for less in (0, 1))
        return ans
    N = SI()
    ans = ketadp(N)
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
from itertools import product


def main():
    n = input()
    numbers = ['3', '5', '7']
    length = len(n)
    answer = 0
    for i in range(3, length + 1):
        for new_num in product(numbers, repeat=i):
            if not all(x in new_num for x in numbers):
                continue
            elif int("".join(new_num)) <= int(n):
                answer += 1
    print(answer)


if __name__ == '__main__':
    main()

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

global ans
ans = 0

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

dfs("")


print(ans)

Solution (Python):
from collections import deque
lista=deque([3,5,7])
count=0
lim=int(input())
while True:
    t=lista.popleft()
    if t>lim:
        break
    c=list(str(t))
    if c.count("3") and c.count("5") and c.count("7"):
        count+=1
    lista.append(10*t+3)
    lista.append(10*t+5)
    lista.append(10*t+7)
print(count)

Solution (Python):
lista=[3,5,7]
count=0
lim=int(input())
while True:
    t=lista.pop(0)
    if t>lim:
        break
    c=list(str(t))
    if c.count("3") and c.count("5") and c.count("7"):
        count+=1
    lista.append(10*t+3)
    lista.append(10*t+5)
    lista.append(10*t+7)
print(count)

Solution (Python):
def cnct(lint,lim):
    global count
    lintlst=list(str(lint))
    if lint>lim:
        return True
    if lintlst.count("3") and lintlst.count("5") and lintlst.count("7"):
        count+=1
    cnct(lint*10+3,lim)
    cnct(lint*10+5,lim)
    cnct(lint*10+7,lim)
list753=[3,5,7]
count=0
b=int(input())
for a in list753:
    cnct(a,b)
print(count)

Solution (Python):
def cnct(lint,lim):
    global count
    lintlst=list(str(lint))
    if lint>lim:
        return True
    if lintlst.count("3") and lintlst.count("5") and lintlst.count("7"):
        count+=1
    cnct(lint*10+3,lim)
    cnct(lint*10+5,lim)
    cnct(lint*10+7,lim)
list753=[3,5,7]
count=0
b=int(input())
for a in list753:
    cnct(a,b)
print(count)

Solution (Python):
def cnct(lint,lim):
    global list753
    global list357
    lint1int=lint*10+3
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2int=lint*10+5
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3int=lint*10+7
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 

list753=[3,5,7]
list357=set()
k=int(input())
for b in list753:
    cnct(b,k)
print(len([x for x in list357 if list(str(x)).count("3")>0 and list(str(x)).count("5")>0 and list(str(x)).count("7")>0]))

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

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

print(calculate(''))

Solution (Python):
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1int=lint*10+3
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2int=lint*10+5
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3int=lint*10+7
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 

def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(input())
for b in list753:
    cnct(b,k)
for c in [x for x in list357]:
    if not D(c):
        list357.remove(c)
print(len(list357))

Solution (Python):
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1int=lint*10+3
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2int=lint*10+5
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3int=lint*10+7
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 

def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(input())
for b in list753:
    cnct(b,k)
for c in [x for x in list357]:
    if not D(c):
        list357.remove(c)
print(len(list357))

Solution (Python):
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1=str(lint)+"3"
    lint1int=int(lint1)
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2=str(lint)+"5"
    lint2int=int(lint2)
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3=str(lint)+"7"
    lint3int=int(lint3)
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 
    lint4="3"+str(lint)
    lint4int=int(lint4)
    if lint4int<=lim and not lint4int in list357:
        list357.add(lint4int)
        cnct(lint4int,lim)
    lint5="5"+str(lint)
    lint5int=int(lint5)
    if lint5int<=lim and not lint5int in list357:
        list357.add(lint5int)
        cnct(lint5int,lim)
    lint6="7"+str(lint)
    lint6int=int(lint6)
    if lint6int<=lim and not lint6int in list357:
        list357.add(lint6int)
        cnct(lint6int,lim)
def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(input())
count=0
for b in list753:
    cnct(b,k)
list333=list(list357)
list333.sort()
for c in [x for x in list333]:
    if not D(c):
        list333.remove(c)
print(len(list333))

Solution (Python):
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1=str(lint)+"3"
    lint1int=int(lint1)
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2=str(lint)+"5"
    lint2int=int(lint2)
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3=str(lint)+"7"
    lint3int=int(lint3)
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 
    lint4="3"+str(lint)
    lint4int=int(lint4)
    if lint4int<=lim and not lint4int in list357:
        list357.add(lint4int)
        cnct(lint4int,lim)
    lint5="5"+str(lint)
    lint5int=int(lint5)
    if lint5int<=lim and not lint5int in list357:
        list357.add(lint5int)
        cnct(lint5int,lim)
    lint6="7"+str(lint)
    lint6int=int(lint6)
    if lint6int<=lim and not lint6int in list357:
        list357.add(lint6int)
        cnct(lint6int,lim)
def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(input())
count=0
for b in list753:
    cnct(b,k)
list333=list(list357)
list333.sort()
for c in [x for x in list333]:
    if not D(c):
        list333.remove(c)
print(len(list333))

Solution (Python):
n = int(input())
d = int(len(str(n)))
c = 0
for k in range(3,d):
  c += 3**k-3*2**k+3
u = int(str(n)[0])
if u >= 8:
  c += 3**d-3*2**d+3
  print(c)
  exit()
if u >= 6:
  c += (3**(d-1)-2**d +1)*2
  i = 2*3**(d-1)
elif u >= 4:
  c += 3**(d-1)-2**d + 1
  i = 3**(d-1)
elif u <= 2:
  print(c)
  exit()
else:
  i = 0
x = [3,5,7]
while True:
  s = 0
  y = [0,0,0]
  p = i
  for j in range(d):
    s += x[p%3]*(10**j)
    y[p%3] = 1
    p = p//3
  if s <= n:
    if sum(y) == 3:
      c += 1
    i += 1
  else:
    break
print(c)

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 sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


n = int(readline())


def dfs(s):
    if int(s) > n:
        return 0
    flag = True
    for check in '753':
        if s.count(check) <= 0:
            flag = False
    if flag:
        x = 1
    else:
        x = 0
    for check in '753':
        x += dfs(s + check)
    return x


print(dfs('0'))

Solution (Python):
from collections import deque

n = int(input())

queue = deque()
queue.append(0)
ans = 0

while queue:
    a = queue.pop()
    if a > n:
        continue
    if all(str(a).count(str(i)) for i in [7, 5, 3]):
        ans += 1
    [queue.append(a * 10 + i) for i in [7, 5, 3]]

print(ans)

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

def is753(s):
    c = collections.Counter(s)
    if c["3"] > 0 and c["5"] > 0 and c["7"] > 0 :
        if c["3"] + c["5"] + c["7"] == len(str(int(s))):
            return True
    return False

def f(s):
    if int(s) > n:
        return 0
    ans=0
    if is753(s):
        ans+=1

    return ans + f(s+"3")+ f(s+"5")+ f(s+"7")

print(f("0"))

Solution (Python):
n = int(input())
def dfs(s,n):
  count = 0
  if s > n:
    return count
  if str(3) in list(str(s)) and str(5) in list(str(s)) and str(7) in list(str(s)):
    count += 1
  count += dfs(10*s + 3,n)
  count += dfs(10*s + 5,n)
  count += dfs(10*s + 7,n)
  return count


print(dfs(3,n) + dfs(5,n) + dfs(7,n))

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())
count = 0

for i in range(1,len(str(N))+1):
  for j in product(['3','5','7'], repeat = i):
    s = ''.join(j)
    if '7' in s and '5' in s and '3' in s and int(s) <= 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):
N = int(input())

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

print(dfs('0'))

Solution (Python):
import bisect

n = int(input())

num = [3, 5, 7]
last_num = [3, 5, 7]
tfs = [3, 5, 7]

for i in range(8):
    new_num = []
    for a in last_num:
        for b in tfs:
            new_num.append(a*10 + b)
    num += new_num
    last_num = new_num

num753 = []

for a in num:
    if len(set(str(a))) == 3:
        num753.append(a)

print(bisect.bisect_right(num753, n))

Solution (Python):
N = int(input())
cnt = []
def dfs(num):
    if num > N:
        return
    if str(num).count('3') >= 1 and str(num).count('5') >= 1 and str(num).count('7') >= 1:
        cnt.append(num)
    dfs(num * 10 + 3)
    dfs(num * 10 + 5)
    dfs(num * 10 + 7)
dfs(0)
print(len(cnt))

Solution (Python):
from collections import deque
n = int(input())
num753 = set()
q = deque([3,5,7])
while q:
    x = q.pop()
    if x <= 10**9:
        num753.add(x)
        q.append(x*10+3)
        q.append(x*10+5)
        q.append(x*10+7)
count = 0
for i in num753:
    if i <= n:
        lst = list(str(i))
        if "3" in lst and "5" in lst and "7" in lst:
            count += 1
print(count)

Solution (Python):
L = []
num = ["3", "5", "7"]
peak = 1
for i in range(10):
  for j in range(peak):
    T = ""
    S = [0, 0, 0]
    tmp = j
    for k in range(i):
      T = T[:] + num[tmp%3]
      S[tmp%3] += 1
      tmp //= 3
    if S[0] * S[1] * S[2] > 0:
      L.append(int(T))
  peak *= 3
L.sort()
N = int(input())
n = len(L)
l, c, r = 0, n // 2, n
pnt = 0
m = max(L)
if m <= N:
  print(n)
else:
  while L[pnt] <= N:
    pnt += 1
  print(pnt)

Solution (Python):
from itertools import product
def myketa(num):
  cc = 0
  while num > 0:
    num //= 10
    cc += 1
  return cc

n = int(input())
keta = myketa(n)
lst = []
for k in range(1, keta+1):
  lst += [''.join(i) for i in product('357', repeat=k)]
print(sum([int(x) <= n and len(set(x)) == 3 for x in lst]))

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

Solution (Python):


n = int(input())


def dfs(cur):
    ret = 0
    for m in ["3", "5", "7"]:
        nex = cur
        nex += m
        if int(nex) <= n:
            if "7" in nex and "5" in nex and "3" in nex:
                ret += 1
            ret += dfs(nex)
    return ret


print(dfs(""))

Solution (Python):
n = list(map(int,list(input())))
len_n = len(n)

dp = [[[0]*8 for i in range(2)] for j in range(len_n)]
base = [0,3,5,7]

for i in range(n[0]+1):
  temp = 0
  ans = 0

  
  if i == 3:
    temp = 1
    ans = 1
  elif i == 5:
    temp = 2
    ans = 1
  elif i == 7:
    temp = 4 
    ans = 1
  elif i == 0:
    temp = 0
    ans = 1
    
  dp[0][n[0] == i][temp] += ans 

for i in range(1,len_n):
  for j in range(2):
    for k in range(8):
      for l in base: 
        if (j == 1) and (n[i] < l):
          continue
          
        if (not(k == 0)) and (l == 0):
          continue
        
        temp = 0
        
        if l == 3:
          temp = 1
        elif l == 5:
          temp = 2
        elif l == 7:
          temp = 4
          
        dp[i][j & (n[i] == l)][k | temp] += dp[i-1][j][k]
        
print(dp[len_n-1][1][7] + dp[len_n-1][0][7])

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

def dfs(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 += 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):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n = int(input())

    d = deque([3,5,7])
    res = 0
    while 1:
        a = d.popleft()
        for i in [3,5,7]:
            b = a*10 + i
            if b <= n:
                d.append(b)
                b = str(b)
                if '3' in b and '5' in b and '7' in b:
                    res += 1
            else:
                print(res)
                exit()

if __name__ == '__main__':
    main()

Solution (Python):
import queue

N = int(input())

q = queue.Queue()
for i in [3,5,7]:
    q.put(i)


cnt = 0
while True:
    n = q.get()
    if n > N:
        break
    elif '3' in str(n) and '5' in str(n) and '7' in str(n):
        cnt += 1
        
    q.put(n * 10 + 3)
    q.put(n * 10 + 5)
    q.put(n * 10 + 7)
print(cnt)

Solution (Python):
def next(n):
    
    s = str(n)
    if s[-1] == "3":
        return int(s[:-1] + "5")
    if s[-1] == "5":
        return int(s[:-1] + "7")
    
    if len(s) == 1:
        return 33
    else:
        s = str(next(s[:-1]))
        return int(s + "3")

def is_753(n):
    
    s = str(n)
    if "3" in s and "5" in s and "7" in s:
        return True
    return False

def next_753(n):
    
    while True:
        n = next(n)
        if is_753(n):
            return n

N = int(input())
ans = 0
n = 357
while n <= N:
    ans += 1
    n = next_753(n)
print(ans)

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect



import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n = int(readline())
  se = set([0])
  ans = []
  for k in range(3,10):
    S = product(['3', '5', '7'], repeat=k)
    for s in S:
      if len(set(s)) == 3:
        i=0
        for j in s:
          i  = i*10 + int(j)
        ans.append(i)
  ans.sort()
  print(bisect(ans,n))
  
  
  
if __name__ == '__main__':
  main()

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):
import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


tmp = []


def func(n):
    global tmp
    if n < 10**9:
        tmp.append(n)
        func(n*10+3)
        func(n*10+5)
        func(n*10+7)
    return tmp


N = int(input())
n = len(func(0))
func(0)
ans = 0
for i in range(n):
    if tmp[i] <= N:
        x = str(tmp[i])
        if ('3' in x) and ('5' in x)and('7' in x):
            ans += 1
print(ans)

Solution (Python):
import itertools
n = int(input())
nagoya = [3,5,7]
i = 1
if n < 357:
    print(0)
    exit()
ans = 0
while(i < 99):
    current = list(itertools.product(nagoya,repeat=i))
    for j in range(len(current)):
        h = int("".join(map(str,(list(current[j])))))
        if len(set(str(h))) == 3:
            if n < h:
                print(ans)
                exit()
            else:
                ans += 1
    i += 1

Solution (Python):
n = int(input())
from itertools import product
ans = 0
for i in range(1, 11):
  for p in product("357", repeat=i):
    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):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
cnt=[]
def dfs(pos,p):
    if p==0:
        
        if int("".join(pos))<=n and "3" in pos and "5" in pos and "7" in pos:
            cnt.append(pos)
    else:
        for j in [3,5,7]:
            dfs(pos+[str(j)],p-1)

if len(str(n))<=2:
    print(0)
    exit()

for i in range(3,len(str(n))+1):
    pos=[]
    p=i
    dfs(pos,p)
print(len(cnt))

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

def generate(p):
    for i in [3, 5, 7]:
        yield p * 10 + i

nums = [3, 5, 7]
ans = 0
num = 0
p = 0

while num < n:
    for a in generate(nums[p]):
        nums.append(a)
        num = a
        if a <= n and set(list(str(a))) == set(list(str(357))):
            ans += 1
    p += 1

print(ans)

Solution (Python):
def DFS(n):
    if len(n)>=3 and len(set(list(n))&{"3","5","7"})==3:
        A.append(int(n))
    if len(n)<10:
        for i in ("3","5","7"):
            DFS(n+i)


n=int(input())
A=[]
for i in ("3","5","7"):DFS(i)
A.sort()

cnt=0
while 1:
    if A[cnt]<=n:cnt +=1
    else:break
print(cnt)

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


def main():
    from collections import deque
    n = int(input())
    ans = dfs('0', n)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def dfs(n,s):
    if int(s)>n:
        return 0
    res=0
    if s.count('7') and s.count('5') and s.count('3')>0:
        res+=1
    for c in '753':
        res+=dfs(n,s+c)
    return res

n=int(input())
print(dfs(n,'0'))

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = str(n)
m = len(str(n))

lst = [3,5,7]
que = deque([3,5,7])
for _ in range(3**m):
    x = que.popleft()
    for j in [3,5,7]:
        que.append(int(str(x)+str(j)))
        lst.append(int(str(x)+str(j)))

ans = 0
for i in lst:
    if i > n:
        break
    cnt = [0]*3
    for j in str(i):
        cnt[(int(j)-1)//3] += 1
    for j in cnt:
        if j == 0:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
import sys
import os
import re
import datetime
import bisect

def DFS(tmpN, N, bitFlags):
    if(tmpN > N):
        return 0

    countAll = 0
    if bitFlags == 0b111:
        countAll += 1

    countAll += DFS(tmpN * 10 + 3, N, bitFlags | 0b100)
    countAll += DFS(tmpN * 10 + 5, N, bitFlags | 0b010)
    countAll += DFS(tmpN * 10 + 7, N, bitFlags | 0b001)

    return countAll


 
N = int(input())

bitFlags = 0b000
result = DFS(0, N, bitFlags)

print(result)

Solution (Python):

def dfs(n,lst,s):
	if int(s) >n:
		return 
	if all([c in s for c in "753"]):
		lst.append(s)
	for c in "753":
		dfs(n,lst,s+c)

lst=[]
n =int(input())
for c in "753":
	dfs(n,lst,c)
print(len(lst))

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