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 = input()
length0 = len(n)
ans = 0

for h in range(3,length0 + 1):
    if h == length0:
        N = n
    else:
        N = "9"*h

    length = len(N)

    dp = [[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(length+1)]
    dp[0][0][0][0][0] = 1

    s1 = [3,5,7]
    for i in range(length):
        max_digit = int(N[i])
        for flag_less in range(2):
            for flag_siti in range(2):
                for flag_go in range(2):
                    for flag_san in range(2):
                        range_digit = s1 if flag_less else [i for i in s1 if i <= max_digit]
                        for d in range_digit:
                            flag_less_next = 0
                            flag_siti_next = 0
                            flag_go_next = 0
                            flag_san_next = 0
                            if flag_less == 1 or d < max_digit:
                                flag_less_next = 1
                            if flag_siti == 1 or d == 7:
                                flag_siti_next = 1
                            if flag_go == 1 or d == 5:
                                flag_go_next = 1
                            if flag_san == 1 or d == 3:
                                flag_san_next = 1
                            dp[i+1][flag_less_next][flag_siti_next][flag_go_next][flag_san_next] += dp[i][flag_less][flag_siti][flag_go][flag_san]

    ans += (dp[length][0][1][1][1] + dp[length][1][1][1][1])

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def dfs_stack(x): #xは探索対象の最大数n
    ans = 0
    stack = []
    stack.append(0)
    while stack:
        i = stack.pop()
        if i > n:
            continue
        ans += 1 if judge(i) else 0
        stack.append(int(str(i) + "3"))
        stack.append(int(str(i) + "5"))
        stack.append(int(str(i) + "7"))
    print(ans)
    
def judge(x:int) -> bool: #753数かを判定する
    if set(str(x)) == {"3", "5", "7"}:
        return True
    else:
        return False    

dfs_stack(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 = 0

def dfs(x:int): #準753数をDFSで列挙
    global ans
    if x > n:
        return
    if judge(x):
        ans += 1
    for i in "357":
        dfs(int(str(x) + i))

def judge(x): #753数かを判定する
    if set(str(x)) == {"3", "5", "7"}:
        return True
    else:
        return False

dfs(0)
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=9):
    p = int("".join(pattern))
    if "0" not in str(p):
        for i in [3, 5, 7]:
            if str(i) not in str(p):
                break
        else:
            if p <= n:
                res += 1
            else:
                break
print(res)

Submission status: Accepted

Solution code:
import math
import collections
from operator import mul
from functools import reduce
import bisect

b=[]
def test(a):
    if len(a)>=8:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
    else:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
        test(a+"3")
        test(a+"5")
        test(a+"7")

#n,m=map(int,input().split())

n=int(input())
test("")
c=[]
b=set(b)
for bi in b:
    if bi.count("3")>0 and  bi.count("5")>0 and bi.count("7")>0 :
        c.append(bi)

c=sorted(list(map(int,c)))
d=bisect.bisect(c,n)
print(d)

Submission status: Accepted

Solution code:
N = int(input())

def dfs(n):
  ans = 0
  if n > N:
    return 0
  else:
    if all(str(n).count(c) > 0 for c in "357"):
      ans = 1
    ans += dfs(10*n + 3)
    ans += dfs(10*n + 5)
    ans += dfs(10*n + 7)
  return ans

print(dfs(0))

Submission status: Accepted

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

def dfs(n):
  global ans
  if n > N:
    return
  else:
    if all(str(n).count(c) > 0 for c in "357"):
      ans += 1
    dfs(10*n + 3)
    dfs(10*n + 5)
    dfs(10*n + 7)

dfs(0)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())#357の木を作る
a=[]
ans=0

def search(count):
    global ans
    #print(count)
    if int(count)>n:#超えたら終わり
        return 
    #print(set(sorted(list(count))))
    if set(sorted(list(count))) =={"0","3","5","7"}:#lsitにかえてそれをsortしてset型に変える
        ans+=1

    for i in "357":
        search(count+i)


search("0")
print(ans)

Submission status: Accepted

Solution code:
N= int(input())
def f(x):
    z=0
    if int(x) >N:
        return 0
    if x.count('3')>0 and x.count('5')>0 and x.count('7')>0:
        z = 1
    z +=f(x+'3')
    z +=f(x+'5')
    z +=f(x+'7')
    return z
print(f('0'))

Submission status: Accepted

Solution code:
N = input()

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

def calc(s):
    c = 0
    for i, j in enumerate(s):
        c +=  int(j) * 10**(num-i-1)
    return c

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

while temp:
    p = temp.pop()
    if len(p)==num:
        if set(list(p)) == {'3', '5', '7'} or set(list(p)) == {'3', '5', '7', '0'}:
            ans += 1
    else:    
        if set(list(p))=={'0'}:
            temp.append(p+'0')
        for i in ('3', '5', '7'):
            if calc(p+i)<=N:
                temp.append(p+i)
            
print(ans)

Submission status: Accepted

Solution code:
def getSpecialNum(x, n):	
	if int(x) > n:
		return 0
	ans = 0
	if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
		ans = 1
	ans += getSpecialNum(x+'3',n)
	ans += getSpecialNum(x+'5',n)
	ans += getSpecialNum(x+'7',n)
	return ans
N = int(input())
print(getSpecialNum('0',N))

Submission status: Accepted

Solution code:
import sys

# import bisect
# from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    nl = len(str(n))
    nums = [3, 5, 7]
    ans = 0



    for i in range(3, nl+1):
        a = itertools.product(nums, repeat=i)
        for elem in a:
            if len(set(elem)) == 3:
                x = ""
                for num in elem:
                    x += str(num)
                x = int(x)
                if x <= n:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
limit = int(input())



def dfs(s):
	if int(s)>limit:
		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 = input()
keta = len(N)
candidate = []

def dfs(s, level):
    if level == keta + 1:
        return
    
    if s=='':
        pass
    else:
        candidate.append(int(s))

    dfs(s + '3', level+1)
    dfs(s + '5', level+1)
    dfs(s + '7', level+1)

dfs('', 0)
ans = 0
for d in candidate:
    group = set(str(d))
    if (group == {'3', '5', '7'}) and (d<=int(N)):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
res =[0]
def rep(n,ans):
    if len(set(str(n)))==3 and n<=N:
        res[0]+=1
        return rep(n*10+3,ans+1)+rep(n*10+5,ans+1)+rep(n*10+7,ans+1)
    elif n<=N:
        for i in [3,5,7]:
            return sum([rep(n*10+i,ans) for i in [3,5,7]])
    else:
        return ans
for i in [3,5,7]:
    rep(i,0)
print(res[0])

Submission status: Accepted

Solution code:
n = 0
ans = 0
def dfs(s):
    ret = 0
    if int(s) <= n:
        if '7' in s and '5' in s and '3' in s:
            ret += 1
        ret += dfs(s+'7')
        ret += dfs(s+'5')
        ret += dfs(s+'3')
    return ret

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

Submission status: Accepted

Solution code:
n = int(input())
def f(s):
  if int(s) > n:
    return 0 #再帰終了
  if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
  	cnt = 1
  else:
  	cnt = 0
  cnt += f(s + "3")
  cnt += f(s + "5")
  cnt += f(s + "7")
  return cnt
  
result = f("0")
print(result)

Submission status: Accepted

Solution code:

N=int(input())
M=["3","5","7"]
S=""

def dfs (S, N):
  global ans
  for m in M:
    T=m+S
    
    if int(T)>N:
      continue
    else:
      
      if len(set(T))==3:
        ans+=1
        
      
      dfs(T, N)
  return
ans=0
dfs(S, N)
print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    N = int(input())
    ans = 0
    for digits in range(1, 10):
        for i in range(3 ** digits):
            num = []
            for j in range(digits):
                k = i
                for _ in range(j):
                    k //= 3
                if k % 3 == 0:
                    num.append(7)
                elif k % 3 == 1:
                    num.append(5)
                else:
                    num.append(3)
            if all(j in num for j in [3, 5, 7]):
                num = reduce(lambda x, i: x * 10 + i, num)
                if num <= N:
                    ans += 1
    print(ans)



main()

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())
ans = 0
for j in range(3, len(str(N))+1):
    for i in product("357", repeat=j):
        x = "".join(i)
        if 357 <= int(x) <= N and len(set(x)) == 3:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def dfs(a):
    if int(a) > N:
        return 0    
    if '7' in a and '5' in a and '3' in a:
        ans = 1
    else:
        ans = 0
    ans += dfs(a+'7')
    ans += dfs(a+'5')
    ans += dfs(a+'3')
    return ans

print(dfs('0'))

Submission status: Accepted

Solution code:
def dfs(s,n):
    if int(s)>n:
        return 0
    ans=1000000
    if(s.count('7')>0 and s.count('5')>0 and s.count('3')>0):
        ans=1
    else:
        ans=0
    for c in '357':
        ans+=dfs(s+c,n);
    return ans
    
    
n=int(input())
print(dfs('0',n))

Submission status: Accepted

Solution code:
N = int(input())
def dfs(s):
    if int(s)>N:#整数にキャスト、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)#再帰、１回のretは0か1
    return ret#retには累積的に結果が加算される
print(dfs("0"))#引数は文字列

'''
>>> s = 'aAaAAbAccdd'
# "A"という文字が何個あるか調べる
>>> s.count('A') #4

>>> a = [True, True, True]
>>> all(a) #True　すべてTrueか？
>>> b = [True, True, False]
>>> all(b) #False
'''

Submission status: Accepted

Solution code:
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    cnt = [0]

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

    print(check("0"))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
from itertools import product
ans = 0
for n in range(3,10):
    for ptn in product('753', repeat=n):
        if '7' not in ptn: continue
        if '5' not in ptn: continue
        if '3' not in ptn: continue
        v = int(''.join(ptn))
        if v <= N:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def dfs(n):
    if int(n) > N:
        return 0

    if all(n.count(i)>0 for i in "753"):
        ret = 1
    else:
        ret = 0
        
    for i in "753":
        ret += dfs(n+i)

    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
n=input()
A=[0,1,2,3,4,5,6,7,8,9]
B=[0,0,0,1,1,2,2,3,3,3]
N=[]
a=0
for i in range(len(n)):
  if a==1:
    N.append(3)
  elif int(n[i]) in {0,3,5,7}:
    N.append(B[int(n[i])])
  else:
    N.append(B[int(n[i])])
    a=1
NN=0
for i in range(len(N)):
  NN=NN+N[-1-i]*4**i
ans=0
for i in range(NN+1):
  S=[]
  j=i
  while j>0:
    k=j%4
    S.append(k)
    j=j//4
  s=set(S)  
  if s=={1,2,3}:
    ans=ans+1
print(ans)

Submission status: Accepted

Solution code:
def search(s, n):
  if int(s) > n:
    return 0
  ans = 1 if (s.count('7') > 0 and s.count('5') > 0 and s.count('3') > 0) else 0
  for c in '753':
    ans += search(s+c,n)
  return ans

N = int(input())
print(search('0',N))

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N = input()
    long=len(N)
    M= int(N)

    seq=(3,5,7)
    cnt=0
    for j in range(3,long+1):
        for i in product(seq,repeat=j):
            if i.count(3)>=1 and i.count(5)>=1 and i.count(7)>=1\
                    and int(''.join(str(j) for j in i))<=M:
                cnt+=1
    print(cnt)




resolve()

Submission status: Accepted

Solution code:
n = int(input())
def f(s):
  if int(s) > n:
    return 0 #再帰終了
  if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
  	cnt = 1
  else:
  	cnt = 0
  cnt += f(s + "3")
  cnt += f(s + "5")
  cnt += f(s + "7")
  return cnt
  
result = f("0")
print(result)

Submission status: Accepted

Solution code:
n=int(input())
from itertools import product as p
l=['7','5','3']
a=[]
for i in range(1,11):
  for j in p(l,repeat=i):
    t=''.join(j)
    if '3' in t and '5' in t and '7' in t:
      a.append(int(t))
a.sort()
from bisect import bisect_right as bi
print(bi(a,n))

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())
ans, L = 0, len(str(N))
for i in range(L + 1):
    for p in product(("7", "5", "3"), repeat=i):
        if "7" in p and "5" in p and "3" in p:
            if (i == L and int(''.join(p)) <= N) or i < L:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
data = deque()
num = [3,5,7]
def shiti(n):
    data.append(n)
    if n<=10**9:
        for i in range(3):
            shiti(n*10+num[i])
shiti(0)
data = list(data)
data = sorted(data)

N = int(input())
cnt = 0
for i in range(len(data)):
    if data[i] > N: break
    ni = list(str(data[i]))
    if "3" in ni and "5" in ni and "7" in ni:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

import itertools
import collections

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

arr = []
for i in range(3,10):
    arr += list(itertools.product(ref, repeat=i))

ans = []
for i in range(len(arr)):
    c = arr[i]
    if '3' in c and '5' in c and '7' in c:
        t = ''.join(list(c))
        if int(t) <= n:
            ans.append(int(t))


ans.sort()
print(len(ans))

Submission status: Accepted

Solution code:
n = int(input()) #入力
def dfs(s): #DFSを使う
    if int(s) > n: #整数にキャスト
        return 0 #再帰の終了条件
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1 #３か、５か、７が、１回は出てくる⇒カウントアップ
    else:
        cnt = 0 #１回ずつ出てこなければ、カウントしない
    cnt += dfs(s + '3') #再帰、３か、５か、７か、を繰り返す
    cnt += dfs(s + '5') #DFSの結果を足している
    cnt += dfs(s + '7')
    return cnt #求めたいのは、出現回数
  
print(dfs('0')) #スタートはゼロ

Submission status: Accepted

Solution code:
n = int(input()) 
def dfs(s):
    if int(s) > n:
        return 0 #再帰の終了条件
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1 #３か、５か、７が、１回は出てくる⇒カウントアップ
    else:
        cnt = 0
    cnt += dfs(s + '3') #再帰、３か、５か、７か、を繰り返す
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt #求めたいのは、出現回数
  
print(dfs('0')) #スタートはゼロ

Submission status: Accepted

Solution code:
n = int(input())
 
def dfs(s):

    if int(s) > n:
        return 0
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1
    else:
        cnt = 0
    cnt += dfs(s + '3')
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt
  
print(dfs('0'))

Submission status: Accepted

Solution code:
def dfs(s): # 文字列 s で始まる七五三数の個数
  if int(s) > 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)
  return ret

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

Submission status: Accepted

Solution code:
import itertools
N=int(input())
words=['3','5','7']
mojiretu=[]
for a in range(1,10):
    answers = list(itertools.product(words, repeat=a))
    for a in answers:
        moji = ''
        for b in a:
            moji += b
        mojiretu.append(moji)
S=[]
for a in mojiretu:
    number=0
    suuji=0
    kazu=0
    for b in a:
        if b=='3':
            number+=1
        elif b=='5':
            suuji+=1
        elif b=='7':
            kazu+=1
    if number>=1 and suuji>=1 and kazu>=1:
        S.append(int(a))
T=[i for i in S if i<=N]
print(len(T))

Submission status: Accepted

Solution code:
n = int(input())

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

print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs("0"))

Submission status: Accepted

Solution code:
# ABC114

N = int(input())
def dfs(num, use):
    if num > N:
        return 0
    cnt = 1 if use == 0b111 else 0
    cnt += dfs(num*10 + 3, use | 0b001)
    cnt += dfs(num*10 + 5, use | 0b010)
    cnt += dfs(num*10 + 7, use | 0b100)
    return cnt
ans = dfs(0, 0)
print(ans)

Submission status: Accepted

Solution code:
# ABC114

N = int(input())
def dfs(num):
    if num > N:
        return 0
    flag = True
    for s in "357":
        if str(num).count(s) >= 1:
            pass
        else:
            flag = False
    ret = 1 if flag else 0

    for c in [3, 5, 7]:
        ret += dfs(num * 10 + c)
    return ret
ans = dfs(0)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
	if int(s) > n:#nより大きいならカウントしない
		#print(int(s))
		return 0

	ret = 1 if all(s.count(c) > 0 for c in '753') else 0
	#753,全てが含まれているなら1
	
	for c in '753':
		ret += dfs(s+c)
		#print(s+c)
	return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
from collections import defaultdict as dic

n = int(input())

data = [0] * 10000000
ans = 0

def judge_753(s):
    judge = 1
    flag = dic(int)
    for i in range(len(s)):
        if s[i] != '7' and s[i] != '5' and s[i] != '3':
            judge = 0
            break
        else:
            flag[int(s[i])] = 1

    if flag[3] != 1 or flag[5] != 1 or flag[7] != 1:
        judge = 0
    return judge

def search_num(num):
    ret = 0
    if num > n:
        return 0
    
    if judge_753(str(num)) == 1:
        ret += 1
    
    ret += search_num(num * 10 + 3) + search_num(num * 10 + 5) + search_num(num * 10 + 7)
    return ret


print(search_num(0))

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())

def shichigosan(n):
    if n != '' and int(n) > N: 
        return 0
    return shichigosan(n+'3') + shichigosan(n+'5') + shichigosan(n+'7') + (1 if len(set(n)) == 3 else 0)

def main():
    print(shichigosan(''))

main()

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
S = []
for i in range(1, 10):
  S += list(product("753",repeat=i))
cnt = 0
for s in S:
  if int("".join(s)) > N:
    continue
  if all(s.count(c) > 0 for c in "753"):
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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


def main():

    print(dfs('0'))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = 0
x = 0
multiplier = 0
result = 0

def solve():
	global x
	global n
	global multiplier
	global result
	#print(x)
	if x>n:
		return
	if x>0:
		if str(3) in str(x) and str(5) in str(x) and str(7) in str(x):
			result+=1
	for i in range(3,8,2):
		x+=(i*(10**multiplier))
		multiplier+=1
		solve()
		multiplier-=1
		x-=(i*(10**multiplier))
	return

n = int(input())
solve()
print(result)

Submission status: Accepted

Solution code:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

N = int(input())


def answer(info, ans):
    if max(ans) > N:
        return ans
    info2 = []
    for i in info:
        for l in ["3", "5", "7"]:
            info2.append(int(str(i) + l))
    ans += info2
    return answer(info2, ans)


a = sorted(list(set(answer([3, 5, 7], [3, 5, 7]))))
num = 0
for i in range(len(a)):
    if a[i] > N:
        print(num)
        break
    elif all(str(a[i]).count(d) > 0 for d in "753"):
        num += 1

Submission status: Accepted

Solution code:
N=int(input())
import queue
que=queue.Queue()
que.put(3);que.put(5);que.put(7)
num=[3,5,7]
cnt=0
while not que.empty():
    v=que.get()
    for n in num:
        nv=v*10+n
        if nv<=N:
            que.put(nv)
            nv_str=str(nv)
            if "3" in nv_str and "5" in nv_str and "7" in nv_str and len(set(nv_str))==3:
                cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s:str):
    if int(s) > N: return 0
    
    cnt = 1 if all(s.count(c) > 0 for c in "753") else 0

    for c in "753":
        cnt += dfs(s + c)
    
    return cnt

print(dfs("0"))

Submission status: Accepted

Solution code:
def dfs(s, n):
    if int(s) > n:
        return 0

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

    for c in '753':
        cnt += dfs(s + c, n)

    return cnt

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

    print(dfs('0', n))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def f(i):
    global ans
    if i == l:
        if 3 in s and 5 in s and 7 in s:
            c = 0
            for j in range(l):
                c += s[j] * 10 ** (l - j - 1)
            if c <= n:
                ans += 1
                #print(c)
        return
    f(i + 1)
    s[i] = 7
    f(i + 1)
    s[i] = 5
    f(i + 1)
    s[i] = 3

n = int(input())
l = len(str(n))
s = [3] * l
ans = 0
f(0)
m = [6, 36, 150, 540, 1806, 5796]
if l >= 4:
    for i in range(l - 3):
        ans += m[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
 
def dfs(s):

    if int(s) > n:
        return 0
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1
    else:
        cnt = 0
    cnt += dfs(s + '3')
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt
 
 
print(dfs('0'))

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())

num_753 = []
for i in range(3, 10):
    for a in product(('7','5','3'), repeat=i):
        if a.count('7') > 0 and a.count('5') > 0 and a.count('3') > 0:
            num_753.append(int(''.join(a)))

num_753.sort()
for i, v in enumerate(num_753):
    if v > n:
        print(i)
        break
else:
    print(i+1)

Submission status: Accepted

Solution code:
from sys import stdin
from collections import deque
def main():
    #入力
    readline=stdin.readline
    N=int(readline())

    #dfs
    count=0
    stack=deque(["0"])
    while len(stack)>=1:
        t=stack.pop()
        for s in "357":
            now=t+s
            if int(now)>N:
                break
            if ("7" in now) and ("5" in now) and ("3" in now):
                count+=1
            stack.append(now)
    
    print(count)

if __name__=="__main__":
    main()

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


def main():
    print(dfs('0'))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 非再帰版
N = int(input())

ans = 0
d = ['']
while d:
  base = d.pop()
  for c in '753':
    num = base + c
    if int(num) <= N and all(_c in num for _c in '753'):
      ans += 1
    
    if int(num) <= N:
      d.append(num)

print(ans)

Submission status: Accepted

Solution code:
# 公式解答
N = int(input())

def solve(s):
  if int(s) > N:
    return 0
  res = 1 if all(s.count(c)>0 for c in '753') else 0 # s自体が七五三数なら+1
  for c in '753':
    res += solve(s + c)
  return res

print(solve('0'))

Submission status: Accepted

Solution code:
def f(n, k):
  num_bit = 3 - bin(k).count('1')
  c = [0, 0, 1, 3]
  return 3**n - num_bit*2**n + c[num_bit]

# k = 0:(), 1:(3), 2(5), 3:(3, 5), 4:(7), 5:(3, 7), 6:(5, 7), 7:(3, 5, 7)
def solve(N, k=0):
  n = len(N)
  num_used = bin(k).count('1')
  if n==0 and num_used==3:
    return 1
  elif n==0 or n+num_used<3:
    return 0
  else:
    a = int(N[0])
    if a > 7:
      return f(n-1, k|1) + f(n-1, k|2) + f(n-1, k|4)
    elif a == 7:
      return f(n-1, k|2) + f(n-1, k|1) + solve(N[1:], k|4)
    elif a > 5:
      return f(n-1, k|2) + f(n-1, k|1)
    elif a == 5:
      return f(n-1, k|1) + solve(N[1:], k|2)
    elif a > 3:
      return f(n-1, k|1)
    elif a == 3:
      return solve(N[1:], k|1)
    else:
      return 0

N = input()
base = sum([f(i, 0) for i in range(3, len(N))])
print(solve(N) + base)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input().strip())
#-----

class Recursion():
    def __init__(self, N :int):
        self.N = N
        self.all_pattern=[]
        
        self.check("")
        
    def check(self, num_str :str):
        for word in "753":
            next_num = num_str + word
            if int(next_num) > self.N:
                continue
            else:
                if all(s in next_num for s in "753"):
                    self.all_pattern.append(next_num)
                self.check(next_num)
        

rec = Recursion(N)
print(len(rec.all_pattern))

Submission status: Accepted

Solution code:

def add_digit(n, d, x):
    """
    nのd桁目にxを挿入する
    357, 1 -> 357x
    357, 2 -> 35x7
    357, 3 -> 3x57
    357, 4 -> x357
    """
    d1 = (10**(d - 1))
    r = n % d1
    h = n // d1
    return h * d1 * 10 + x * d1 + r


def submit():
    n = int(input())
    satisfied = {357, 375, 537, 573, 735, 753}

    stop = False
    curr_d = 3
    ans = 0
    while True:
        for s in satisfied:
            if s <= n:
                ans += 1
            else:
                stop = True
        
        if stop:
            break

        new_satisfied = []
        for s in satisfied:
            for i in range(1, curr_d + 2):
                new_satisfied.append(add_digit(s, i, 3))
                new_satisfied.append(add_digit(s, i, 5))
                new_satisfied.append(add_digit(s, i, 7))
        satisfied = set(new_satisfied)
        curr_d += 1

    print(ans)


if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:

def add_digit(n, d, x):
    """
    nのd桁目にxを挿入する
    357, 1 -> 357x
    357, 2 -> 35x7
    357, 3 -> 3x57
    357, 4 -> x357
    """
    d1 = (10**(d - 1))
    r = n % d1
    h = n // d1
    return h * d1 * 10 + x * d1 + r


def submit():
    n = int(input())
    satisfied = {357, 375, 537, 573, 735, 753}

    stop = False
    curr_d = 3
    ans = 0
    while True:
        for s in satisfied:
            if s <= n:
                ans += 1
            else:
                stop = True
        
        if stop:
            break

        new_satisfied = []
        for s in satisfied:
            for i in range(1, curr_d + 2):
                new_satisfied.append(add_digit(s, i, 3))
                new_satisfied.append(add_digit(s, i, 5))
                new_satisfied.append(add_digit(s, i, 7))
        satisfied = set(new_satisfied)

    print(ans)


if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
import itertools as itr

num = int(input())

a = ['0', '3', '5', '7']
b = ['0', '3', '5', '7']
c = ['0', '3', '5', '7']
d = ['0', '3', '5', '7']
e = ['0', '3', '5', '7']
f = ['0', '3', '5', '7']
g = ['0', '3', '5', '7']
h = ['0', '3', '5', '7']
i = ['0', '3', '5', '7']

cnt = 0
for j,k,l,m,n,o,p,q,r in itr.product(a,b,c,d,e,f,g,h,i):
    num2 = int(j+k+l+m+n+o+p+q+r)
    num2 = str(num2)
    if '0' not in num2:
        if '3' in num2 and '5' in num2 and '7' in num2:
            num2 = int(num2)
            if num >= num2:
                cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N=int(input())

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

print(dfs("0"))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

def judge(number):
    def digit(check_num , number):
        if int(check_num) > number:
            return 0
        
        if all(check_num.count(digit_num) > 0 for digit_num in "753"):
            # print("dp:",check_num)
            count = 1
        else:
            # print("no_dp:",check_num)
            count = 0
        
        for add_num in "753":
            count = count + digit(check_num + add_num , number)
            # print("conut:{},add_num:{}".format(count,add_num))
        return count
        
    print(digit("0",number))

def main():
    number = int(input())
    judge(number)
    
if __name__ == "__main__":
    main()