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



Sample input:
575


Sample output:
4

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
    #print(ans,d)
    #input()
    i=i+1
for i in range(len(ans)):
    if N>=ans[i]:
        cnt=cnt+1
    else:
        break
print(cnt)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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'))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

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)
        #print(a,sa,n)
        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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#3~len(N)の重複組み合わせSでも楽に解ける
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])

Submission status: Accepted

Solution code:
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)
#print(l,r)
#print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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'))

Submission status: Accepted

Solution code:
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()
        #print(val)
        if len(val) < 11:
            #print(len(str(val)))
            for i in range(3):
                val2 = val + d[i]
                #print(val3[-1])
                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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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):
    # print(x)
    ans = 0
    c = int(x)
    if c > N:
        return 0
    if check(x):
        ans += 1
    # if ans == 1:
    #     print(x)
    for s in '357':
        ans += rec(x + s)
    return ans

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

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
    #nya = 0
    d.append(0)
    LIST = []
    n = int(input())
    flag = False
    while True:

        a = d.popleft()
        #print(a)
        if a > n:
            #print(a,nya)
            print(cnt)
            exit()        #print(n,a)
        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()

Submission status: Accepted

Solution code:
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)
# print(ans_list)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())


def dfs(s):
    if int(s) > n:  # 文字列 s で始まる七五三の個数
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0  # s 自体が七五三数なら +1
    for c in "753":
        ret += dfs(s + c)
    return ret


print(dfs("0"))  # 本当は dfs('') と書きたいが4行目でのエラーを防ぐために仕方なく

Submission status: Accepted

Solution code:
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'))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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'))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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'))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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'))

Submission status: Accepted

Solution code:
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'))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s): # 文字列 s で始まる七五三数の個数
  if int(s) > N: # Nを超えるまで実行
    return 0
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
  for c in '753':
    ret += dfs(s + c) # 753の1文字を足して実行
  return ret # 753数がいくつあるかカウント

print(dfs('0')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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"))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
    #print(now)
    if int(now)>N:
      print(count)
      exit()
    que.append(now)
    if len(set(now))==3:
      count+=1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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"))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(''))

Submission status: Accepted

Solution code:
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)
    #print(L)
    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
"""

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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