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):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]




'''
N = ii()

shiki = [1]
for i in range(10):
    tmp = shiki[-1]*3
    shiki.append(tmp)

ele = [3, 5, 7]
l = []
for keta in range(3, 10):
    maxx = shiki[keta]
    for i in range(maxx):
        ten = 10**(keta-1)
        tmp = 0
        for j in reversed(range(keta)):
            tmp += ele[i//shiki[j]] * ten
            i %= shiki[j]
            ten //= 10
        l.append(tmp)

cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ['3', '5', '7']):
        cnt += 1
            
print(cnt)
'''

def n_shinsu(k, n):
    bi=''
    while n!=0:
        bi+=str(n%abs(k))
        if k<0:n=-(-n//k)
        else:n=n//k
    return bi[::-1]

N = ii()
maxx = 8
l = []
ele = [3, 5, 7]
for keta in range(3, 10):
    maxx = (maxx+1) * 3 - 1
    for i in range(maxx):
        tmp = n_shinsu(3, i).zfill(keta)
        ten = 1
        num = 0
        for moji in tmp[::-1]:
            num += ele[int(moji)] * ten
            ten *= 10
        l.append(num)

cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ['3', '5', '7']):
        cnt += 1
            
print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]





N = ii()

shiki = [1]
for i in range(10):
    tmp = shiki[-1]*3
    shiki.append(tmp)

ele = [3, 5, 7]
l = []
for keta in range(3, 10):
    maxx = shiki[keta]
    for i in range(maxx):
        ten = 10**(keta-1)
        tmp = 0
        for j in reversed(range(keta)):
            tmp += ele[i//shiki[j]] * ten
            i %= shiki[j]
            ten //= 10
        l.append(tmp)

cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ['3', '5', '7']):
        cnt += 1
            
print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]







N = ii()
ele = [3, 5, 7]
l = []

def dfs(num, flag):
    if num > N:
        return 
    if flag == 7:
        l.append(num)
    num *= 10
    for i, e in enumerate(ele):
        dfs(num+e, flag | 1<<i)

dfs(0, 0)
print(len(l))

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]


import itertools 

N = ii()
l = []

for keta in range(3, 10):
    for koho in itertools.product(['3', '5', '7'], repeat=keta):
        l.append(int(''.join(koho)))

l.sort()

ele = ['3', '5', '7']
cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ele):
        cnt += 1

print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 

import itertools 
from collections import deque

N = ii()
ele = [3, 5, 7]
l = []

def dfs(num, flag3, flag5, flag7):
    
    if num > N:
        return 
    if flag3 is flag5 is flag7 is True:
        l.append(num)
    num *= 10
    dfs(num+3, True, flag5, flag7)
    dfs(num+5, flag3, True, flag7)
    dfs(num+7, flag3, flag5, True)

dfs(0, False, False, False)
print(len(l))

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 

import itertools 
from collections import deque

N = ii()
que = deque([33, 35, 37, 53, 55, 57, 73, 75, 77])
ele = ['3', '5', '7']

ind = 0
while True:
    num = que[ind] * 10
    que.append(num + 3)
    que.append(num + 5)
    que.append(num + 7)
    if len(str(num)) >= 10:
        break
    ind += 1

ind = bisect.bisect_right(que, N)

ele = ['3', '5', '7']
cnt = 0
for i in range(ind):
    tmp = str(que[i])
    for e in ele:
        if e not in tmp:
            cnt += 1
            break

print(ind - cnt)

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

  def bit_mask(n):
    b, d = 4, 9  
    arr = []
    for i in range(d-1, -1, -1):
      arr.append(n // (b**i))
      n = n % (b**i)
    ret = str(int(''.join(map(str, arr))))
    return ret

  def decode753(arr):
    ret = ''.join(map(str, arr)).replace('3','7').replace('2','5').replace('1','3')
    return int(ret)

  ans = 0
  b, d = 4, 9
  for m in range(b**d):
    mask = bit_mask(m)
    if mask.count('0') == 0 and mask.count('1') > 0 and mask.count('2') > 0 and mask.count('3') > 0:
      x = decode753(mask)
      if x <= n: ans += 1
      else: break
  print(ans)

abc114_c()

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

def dfs(s):
    global N
    n = int(s)
    if n>N:
        return 0
    ans = 0
    if n>=357 and all(s.count(c) for c in "753"):
        ans = 1
    ans = ans + dfs(s+"7")+dfs(s+"5")+dfs(s+"3")
    return ans

print(dfs("0"))

Solution (Python):
n=int(input())
keta=len(str(n))

cnt=0

kouho=set([])

def saiki(x):
    global kouho
    global keta
    if len(x)==keta:
        return 1

    for s in ["3","5","7"]:
        temp=x+s
        kouho.add(temp)
        saiki(temp)

saiki("")

cnt=0
for item in kouho:
    if "3" in item and "5" in item and "7" in item:
        if int(item)<=n:
            cnt+=1

print(cnt)

Solution (Python):
from collections import deque
n = int(input())
a =deque([3,5,7])
s = 0
while  len(a)!=0 :
  b = a.popleft()
  if b<=n:
    a.append(10*b+3)
    a.append(10*b+5)
    a.append(10*b+7)
    if len(set([j for j in str(b)]))==3:
      s += 1
print(s)

Solution (Python):

import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
answer = 0
digit = len(str(N))

for d in range(3, digit+1):
    for x in itertools.product(['3', '5', '7'], repeat=d):
        if len(set(x)) != 3:
            continue
        y = int(''.join(x))
        if y <= N:
            answer += 1

print(answer)

Solution (Python):
s=input()
l=len(s)
n=int(s)
b=[357,375,537,573,753,735]
if l<=3:
    print(sum(1 for j in b if j<=n));exit()
from itertools import product as pr
ans=0
for k in range(3,l+1):
    for i in pr(("7","5","3"),repeat=k):
        if len(set(i))==3:ans+=int(int("".join(i))<=n)
print(ans)

Solution (Python):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())

    que = queue.Queue()
    que.put('3')
    que.put('5')
    que.put('7')

    res = 0
    while not que.empty():
        i = que.get()
        if int(i) <= N:
            if ('3' in i) and ('5' in i) and ('7' in i):
                res += 1
            que.put(i + '3')
            que.put(i + '5')
            que.put(i + '7')
        else:
            break

    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def rec(s, n):
    c = 0
    if s == '':
        s = '0'
    if int(s) > n:
        return 0
    if len(set(s)) == 4:
        
        c += 1
    for i in '357':
        w = s + i
        c += rec(w, n)
    return c

def main():
    n = int(input().strip())
    print(rec('', n))

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
nana=[7,5,3]
def check(x):
    s=str(x)
    d=1 if all(s.count(str(nana[i]))>=1 for i in range(3) ) else 0
    return d

def dfs(x):
    res=0
    if x>n:
        return 0
    if check(x):
        res+=1
    for i in range(3):
        res+=dfs(10*x+nana[i])
    return res
 
print(dfs(0))

Solution (Python):
n=int(input())
nana=[7,5,3]
def check(x):
    s=str(x)
    d=1 if all(s.count(str(nana[i]))>=1 for i in range(3) ) else 0
    return (d and x<=n)

def dfs(x):
    res=0
    if x>n:
        return 0
    if check(x):
        res+=1
    for i in range(3):
        res+=dfs(10*x+nana[i])
    return res
 
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):


answers = []

def plus(length, target):
    if len(target) == length:
        if not (("3" not in target) or ("5" not in target) or ("7" not in target)):
            answers.append(int(target))
            return
    else:
        for i in ["3","5","7"]:
            next = target + i
            plus(length, next)

def main(N):
    for d in range(3,10):
        plus(d, "")
    print(len([a for a in answers if a<=N]))

if __name__ == "__main__":
    N = int(input())
    main(N)

Solution (Python):
n=int(input())
def dfs(k,n):
  if k>n:
    return 0
  c=0
  if '3' in str(k) and '5' in str(k) and '7' in str(k):
    c=1
  l=len(str(k))
  return c+dfs(k+3*10**l,n)+dfs(k+5*10**l,n)+dfs(k+7*10**l,n)
print(dfs(3,n)+dfs(5,n)+dfs(7,n))

Solution (Python):


data = int(input())

def asd(nim):
  if int(nim) > data:
    return 0
  ret = 1 if all(nim.count(c) > 0 for c in "753") else 0
  for c in "753":
    ret += asd(nim+c)
  return ret

print(asd("0"))

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

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

ans = 0
a = [3, 5, 7]
i = 0
while a[i] <= N:
    x10 = a[i] * 10
    a.append(x10+3)
    a.append(x10+5)
    a.append(x10+7)
    i += 1

for j in range(i):
    s = str(a[j])
    if "3" in s and "5" in s and "7" in s:
        ans += 1

print(ans)

Solution (Python):
from collections import deque
N=int(input())
ans=[]
d=deque()
i=0
cnt=0
d.append(3)
d.append(5)
d.append(7)
while i<50000:
    v=d.popleft()
    buf=list(str(v))
    if len(set(buf))==3:
        ans.append(v)
    d.append(v*10+3)
    d.append(v * 10 + 5)
    d.append(v * 10 + 7)
    
    
    i=i+1
for i in range(len(ans)):
    if N>=ans[i]:
        cnt=cnt+1
    else:
        break
print(cnt)

Solution (Python):
def saiki(n, s, ks, loops):

    count = ks + s
    ans = 0

    if int(count) > int(n):
        return 0
    elif "3" in count and "5" in count and "7" in count:
        ans += 1

    for i in loops:
        ans += saiki(n, i, count, loops)

    return ans

def b755(n):


    loops = ["3", "5", "7"]
    ans = 0

    for i in loops:
        ans += saiki(n, i, "", loops)

    return ans

def main():
    n = str(input())
    print(b755(n))

if __name__ == '__main__':
    main()

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


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

print(func('0'))

Solution (Python):
def dfs(n,a,s):
    global ans
    temp = int(s)
    if temp > n:
        return
    if "7" in s and "5" in s and "3" in s and n>=temp:
        ans += 1
    for i in a:
        dfs(n,a,s+i)
ans = 0
a = ["7","5","3"]
n = int(input())
s = "0"
dfs(n,a,s)
print(ans)

Solution (Python):
N = int(input())
ans = []
def recur(x, flag3, flag5, flag7):
    if(x > N):
        return
    if(flag3 and flag5 and flag7 ):
        ans.append(x)
    recur(10*x+3, True, flag5, flag7)
    recur(10*x+5, flag3, True, flag7)
    recur(10*x+7, flag3, flag5, True)


recur(0,False,False,False)
print(len(ans))

Solution (Python):
from collections import deque
N = int(input())
ans = 0
A = "357"
Q = deque(["3","5","7"])
while Q:
    q = Q.pop()
    x = int(q)
    if x>N:continue
    if len(set(q))==3:ans+=1
    for a in A:
        Q.append(q+a)
print(ans)

Solution (Python):
n=int(input())
D=len(str(n))
A=["7","5","3"]
ans=0
def sgs(k="",d=0,U=[0,0,0]): 
    global ans
    if d>0:
        if int(k)<=n and all([u for u in U]):
            ans+=1
    if d<D:
        for i in range(3):
            newU=[0,0,0]
            for j in range(3):
                if i==j:
                    newU[j]=1
                else:
                    newU[j]=U[j]
            sgs(k+A[i],d+1,newU)
        
sgs()
print(ans)

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

def check(k):
    h3 = h5 = h7 = False
    while k:
        d = k%10
        h3 |= d == 3
        h5 |= d == 5
        h7 |= d == 7
        k //= 10
    return h3 and h5 and h7

ans = 0
stack = [3,5,7]
while stack:
    k = stack.pop()
    if k > N:
        continue
    if check(k):
        ans += 1
    stack.extend([k*10+3, k*10+5, k*10+7])

print(ans)

Solution (Python):
import itertools
n = int(input())
list1 = []
def f(k):
   list2 =  ["".join(x) for x in itertools.product(["3","5","7"],repeat=k) ]
   return [int(x) for x in list2 if ("3" in x) and ("5" in x) and ("7" in x)]

for i in range(3,10):
  list1 += f(i)

print(sum(1 for x in list1 if x<=n))

Solution (Python):
from itertools import product
n=int(input())
ans=0
for i in range(3,10):
    l=list(product(["3","5","7"],repeat=i))
    for j in l:
        if len(set(j))==3:
            if int("".join(list(j)))<=n:
                ans+=1
print(ans)

Solution (Python):
from itertools import product
n=int(input())
ans=0
for i in range(3,10):
    l=list(product(["3","5","7"],repeat=i))
    for j in l:
        ans+=(int("".join(list(j)))<=n and len(set(j))==3)
print(ans)

Solution (Python):










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    nl = len(str(n))

    from collections import deque
    que = deque()

    selec = [3,5,7]
    que.append(0)
    ans = 0
    swi = False
    while que:
        a = que.popleft()
        sa = str(a)
        
        for i in range(3):
            que.append(a*10 + selec[i])
        if a > n:
            break
        elif (not swi) and sa.count('5') >= 1 and sa.count('7') >= 1 and sa.count('3') >= 1:
            swi = True
            ans += 1
        elif sa.count('5') >= 1 and sa.count('7') >= 1 and sa.count('3') >= 1:
            ans += 1
    print(ans)

if __name__ == '__main__':
  main()

Solution (Python):
from itertools import product
n=int(input())
ans=[]
for i in range(3,10):
    l=list(product(["3","5","7"],repeat=i))
    for j in l:
        if len(set(j))==3:
            ans.append(int("".join(list(j))))

ans.sort()
m=len(ans)
l,r=0,m-1
while l+1<r:
    k=(l+r)//2
    if ans[k]<n:
        l=k
    elif ans[k]>n:
        r=k
    else:
        l,r=k,k
        break
if ans[l]>n:
    print(l)
elif ans[r]<=n:
    print(r+1)
else:
    print(l+1)

Solution (Python):

from collections import deque
N=int(input())
d=deque(["3","5","7"])
A=["3","5","7"]
c=0
while True:
  s=d.popleft()
  if int(s)>N:
    print(c)
    exit()
  if len(set(s))==3:
    c+=1
  d.extend([s+i for i in A])

Solution (Python):
from itertools import product
n=int(input())
ans=[]
for i in range(3,10):
    l=list(product(["3","5","7"],repeat=i))
    for j in l:
        if len(set(j))==3:
            ans.append(int("".join(list(j))))

ans.sort()
m=len(ans)
l,r=0,m-1
while l+1<r:
    k=(l+r)//2
    if ans[k]<n:
        l=k
    elif ans[k]>n:
        r=k
    else:
        l,r=k,k
        break
if ans[l]==n:
    print(l+1)
elif ans[r]==n:
    print(r+1)
elif ans[l]>n:
    print(l)
elif ans[r]<n:
    print(r+1)
elif ans[l]<n:
    print(l+1)

Solution (Python):
ls = ["7","5","3"]
ws = set()
def rec(pre):
    if len(pre)==l:return
    for w in ls:
         s = pre+w
         ws.add(s)
         rec(s)
    return
n = int(input())
l = len(str(n))
rec("")
ans = 0
for w in ws:
    if w.count("7")*w.count("5")*w.count("3") !=0:
         if int(w)<=n:ans+=1
print(ans)

Solution (Python):
import itertools

n = int(input())
digits = [3, 5, 7]

def count(digits, n):
	A = []
	p = 3
	while True:
		for tup in itertools.product(digits, repeat=p):
			a = int(''.join(list(map(str, tup))))
			if a > n:
				break
			A.append(a)
		else:
			p += 1
			continue
		break
	return A

lst = count(digits, n)

cnt = 0
for v in lst:
	if all(str(v).count(c) > 0 for c in '753'):
		cnt += 1

print(cnt)

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

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

print(dfs('0'))

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

lis = set()
def dfs():
    d = ['3','5','7']
    que = deque(['3','5','7'])
    while len(que) != 0:
        val = que.pop()
        
        if len(val) < 11:
            
            for i in range(3):
                val2 = val + d[i]
                
                l = list(val2)
                if '3' in l and '5' in l and '7' in l:
                    lis.add(int(val2))
                que.append(val2)

    return lis
lis = dfs()
ans = 0
for i in lis:
    if int(i) <= n:
        ans += 1
print(ans)

Solution (Python):
from collections import deque
n=int(input())
d=deque(['3','5','7'])
def dfs(d,n,lst):
  while len(list(d))>0:
    for i in range(len(list(d))):
      s=d.popleft()
      for j in ['3','5','7']:
        if int(s+j)<=n:
          lst.append(s+j)
          d.append(s+j)
  return lst
lst=dfs(d,n,[])
num=0
for i in lst:
  if len(set(list(i)))==3:
    num+=1
print(num)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

ans = 0
c = ['3', '5', '7']
N = 0

def check(l):
    return len(set(l)) == 4

def nummaker(k, n):
    global ans
    if k == 0:
        q = int(''.join(n))
        if q > N:
            print(ans)
            sys.exit(0)
        if check(n):
            ans += 1
        return
    for i in c:
        m = n[:]
        m.append(i)
        nummaker(k-1, m)

def rec(x):
    
    ans = 0
    c = int(x)
    if c > N:
        return 0
    if check(x):
        ans += 1
    
    
    for s in '357':
        ans += rec(x + s)
    return ans

def main():
    global N
    N = int(input().strip())
    print(rec('0'))
    
        

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

ans = 0
c = ['3', '5', '7']
N = 0

def check(l):
    return len(set(l)) == 3

def nummaker(k, n):
    global ans
    if k == 0:
        q = int(''.join(n))
        if q > N:
            print(ans)
            sys.exit(0)
        if check(n):
            ans += 1
        return
    for i in c:
        m = n[:]
        m.append(i)
        nummaker(k-1, m)

def main():
    global N
    N = int(input().strip())
    for i in range(1, 11):
        nummaker(i, [])

if __name__ == '__main__':
    main()

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

ans = 0
a = [3, 5, 7]
i = 0
while a[i] <= N:
    x10 = a[i] * 10
    a.append(x10+3)
    a.append(x10+5)
    a.append(x10+7)
    i += 1

for j in range(i):
    s = str(a[j])
    if "3" in s and "5" in s and "7" in s:
        ans += 1

print(ans)

Solution (Python):
import copy
from collections import deque

n = int(input())

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

count = 0
d = deque()
d.append(([],set()))

while len(d) != 0:
  s,used = d.pop()
  if len(s) != 0 and int(''.join(s)) > n:
    continue
  
  if len(used) == 3:
    count += 1  
    
  for c in array:
    cp_s = copy.deepcopy(s)
    cp_s.append(c)    
    if len(used) == 3:
      d.append((cp_s,used))
    
    else:
      cp_used = copy.deepcopy(used)
      cp_used.add(c)
      d.append((cp_s,cp_used))
  
print(count)

Solution (Python):
import sys
from itertools import product
from bisect import bisect_right as bi_r

cand = [int(''.join(p)) for i in range(3, 10) 
        for p in product('357', repeat=i) 
        if len(set(p)) == 3]

n = int(sys.stdin.readline().rstrip())

def main():
    print(bi_r(cand, n))

if __name__ ==  '__main__':
    main()

Solution (Python):
import sys
from itertools import product
from bisect import bisect_right as bi_r

cand = [int(''.join(p)) for i in range(3, 10) for p in product('357', repeat=i) if len(set(p)) == 3]

n = int(sys.stdin.readline().rstrip())

def main():
    print(bi_r(cand, n))

if __name__ ==  '__main__':
    main()

Solution (Python):





mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    from collections import deque
    d = deque()
    lc = [3,5,7]
    cnt = 0
    
    d.append(0)
    LIST = []
    n = int(input())
    flag = False
    while True:

        a = d.popleft()
        
        if a > n:
            
            print(cnt)
            exit()        
        if len(str(a)) == 3 and (not flag):

            flag = True
        if flag and (str(a).count('3') >= 1 and str(a).count('5') >= 1 and str(a).count('7') >= 1):
            cnt += 1
        for i in range(3):
            nya = a * 10 + lc[i]
            d.append(nya)
if __name__ == '__main__':
  main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

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

ans_list = []
ans = 0
while q:
    a = q.pop()

    if len(a) != 0:
        if int(a) <= N:
            cnt = 0
            for i in [3, 5, 7]:
                if a.count(str(i)) >= 1:
                    cnt += 1
            if cnt == 3:
                ans += 1
                ans_list.append(a)

        
            for i in [3, 5, 7]:
                b = deepcopy(a)
                b += str(i)
                q.append(b)

print(ans)

Solution (Python):
from queue import Queue
N = int(input())
q = Queue()
L = [3,5,7]
cnt = 0
for i in L:
    q.put(i)
while True:
    num = q.get()
    if num > N:
        break
    for i in L:
        q.put(num * 10 + i)
    num = str(num)
    if '3' in num and '5' in num and '7' in num:
        cnt += 1
print(cnt)

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


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


print(dfs("0"))

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()

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 collections import deque
n = int(input())
num = []

q = deque([3,5,7])
while q:
    tar = q.popleft()
    num.append(tar)
    if len(str(tar)) >= 9:
        pass
    else:
        q.append(tar*10+3)
        q.append(tar*10+5)
        q.append(tar*10+7)
ans = 0
for i in num:
    s = set(list(str(i)))
    if len(s) != 3:
        pass
    elif i <= n:
        ans += 1
print(ans)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque

N = input()
digits = len(N)
if digits <= 2 or int(N[0]) <= 2:
    print(0)
    sys.exit()

ans = 0

queue = deque([("3", 1, 0, 0), ("5", 0, 1, 0),  ("7", 0, 0, 1)])

while queue:

    current, flg3, flg5, flg7 = queue.popleft()

    if len(current) > digits:
        continue    
    if flg3 and flg5 and flg7 and int(current) <= int(N):
        ans += 1

    queue.append((current+"3", 1, flg5, flg7))
    queue.append((current+"5", flg3, 1, flg7))    
    queue.append((current+"7", flg3, flg5, 1))
    
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()

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

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

    return ret

print(dfs('0'))

Solution (Python):
n = int(input())
ans = 0
import sys
sys.setrecursionlimit(10**9)
def func(a):
  global ans
  if a <= n and '3' in str(a) and '5' in str(a) and '7' in str(a):
    ans += 1
  if a < n:
    func(int(str(a)+'3'))
    func(int(str(a)+'5'))
    func(int(str(a)+'7'))
func(3)
func(5)
func(7)
print(ans)

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import deque

def main():
    n = II()
    cnt = 0
    dq = deque(['3', '5', '7'])
    while dq:
        d = dq.popleft()
        if int(d) > n: break
        if '7' in d and '5' in d and '3' in d:
            cnt += 1
        dq.append(d+'3')
        dq.append(d+'5')
        dq.append(d+'7')
    print(cnt)

if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import deque

N = int(input())


q = deque([str(3), str(5), str(7)])
cnt = 0

while(int(q[0]) <= N):
  x = q.popleft()
  if(('3' in x) and ('5' in x) and ('7' in x)):
    cnt += 1
    
  x3 = x + '3'
  x5 = x + '5'
  x7 = x + '7'
  q.append(x3)
  q.append(x5)
  q.append(x7)
  
print(cnt)

Solution (Python):
from collections import deque


def bfs(N):
    coord = ["3", "5", "7"]
    q = deque(coord)
    ans = 0
    while q:
        s = q.pop()

        for c in coord:
            ns = s + c
            if int(ns) <= N:
                if "3" in ns and "5" in ns and "7" in ns:
                    ans += 1
                q.append(ns)
            else:
                continue

    return ans


N = int(input())
print(bfs(N))

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

Solution (Python):
N = int(input())
ans = []
def f(n):
    if int(n) > N:
        return
    if '7' in n and '5' in n and '3' in n:
        ans.append(n)
    f(n+'7')
    f(n+'5')
    f(n+'3')
f('7')
f('5')
f('3')
print(len(ans))

Solution (Python):
n=int(input())
import itertools as it

ans=0
for i in range(3,len(str(n))+1):
    pr=list(it.product("753",repeat=i))
    
    for j in pr:
        s=set(j)
        if len(s)==3:
            num=int(''.join(j))
            if num<=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):
n = int(input())


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

    return res


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 itertools
n = int(input())
l = [3,7,5]
c = 0
for i in range(3,10):
    for j in itertools.product(l, repeat=i):
        if len(set(j)) == 3 and int(''.join(map(str,j))) <= n:
            c += 1
print(c)

Solution (Python):
def main():
    from collections import deque

    N = int(input())

    dq = deque()
    dq.append(0)

    ans = 0
    while dq:
        x = dq.popleft()
        for a in (7, 5, 3):
            t = x * 10 + a
            if t > N: continue
            if all(c in str(t) for c in '753'):
                ans += 1
            dq.append(t)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
ans=[]
s=[3,5,7]
def dfs(n):
    if n>=10**9:
        return
    ans.append(n)
    for i in s:
        dfs(10*n+i)
dfs(3)
dfs(5)
dfs(7)
N=int(input())
cnt=0
for i in ans:
    if i<=N and len(set(str(i)))==3:
        cnt+=1
print(cnt)

Solution (Python):
from itertools import product

num753 = ['7', '5', '3']
ans = 0
n = int(input())
for i in range(3, 10):
    for j in product(num753, repeat=i):
        if all(x in j for x in num753) and int(''.join(j)) <= n:
            ans += 1
print(ans)

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(str(a)) == {'3', '5', '7'}:
        c += 1
print(c)