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:
import sys
from itertools import combinations
input = sys.stdin.readline

N = int(input())
leng = len(str(N))
if leng <= 2:
    print(0)
    exit()

def f(N, l, stri):
    if l == 0:
        if int(stri) <= N and '7' in stri and '5' in stri and '3' in stri:
            return 1
        else:
            return 0
    ans = 0
    for i in ['7', '5', '3']:
        ans += f(N, l-1, stri + i)
    return ans

ans = 0
for l in range(3, leng+1):
    ans += f(N, l, '')

print(ans)

Submission status: Accepted

Solution code:
N=int(input())

nums=[]
all=set(['3','5','7'])
def dfs(x):
  if x>N:
    return
  if x>=357:
    if len(all-set(list(str(x))))==0:
      nums.append(x)
  for i in (3,5,7):
    dfs(x*10+i)

dfs(0)
print(len(nums))

Submission status: Accepted

Solution code:
n = int(input())

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

def dfs(s):
    if int(s) > n: #nを超えたら戻る
        return 0
    ret = 1 if all(s.count(c) > 0 for c in list753) else 0 #sの中に3,5,7の全てが存在するならretに1を、そうでないなら0を
    for c in list753: #sの末尾に3,5,7を加えてdfs
        ret += dfs(s+c)
    return ret #最後のループではretを関数外に返す。それ以外では、ret += のところに返す。
print(dfs("0"))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

N = int(input())
N_str = str(N)

ans=0
num = ["0","3","5","7"]
for s in itertools.product(num,num,num,num,num,num,num,num,num):
    n = int("".join(s))
    c3 = str(s).count("3")
    c5 = str(s).count("5")
    c7 = str(s).count("7")
    #print(s,n,c3,c5,c7)
    if n <= N and c3>=1 and c5>=1 and c7>=1 and c3+c5+c7==len(str(n)):
        ans+=1
        #print(n)
    elif n>N:
        break
print(ans)

Submission status: Accepted

Solution code:
#再帰関数
N = int(input())
def sft(s):
    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 += sft(s+c)
    return cnt
    
print(sft('0'))

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    cnt = [0, 1]['7' in s and '5' in s and '3' in s]
    for x in '753':
        cnt += dfs(s + x)
    return cnt

print(dfs('0'))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)
n=int(input())
m=len(str(n))
L=[]
def dfs(i,num):
    if i==m+1:
        return
    if 0<i<m+1:
        if len(set(num))==3 and int(num)<=n:
            L.append(int(num))
    dfs(i+1,num+'3')
    dfs(i+1,num+'5')
    dfs(i+1,num+'7')
dfs(0,'')
print(len(L))

Submission status: Accepted

Solution code:
N = int(input())
n = ["3", "5", "7"]
l = 0
r = 3
x = 1
flag = True
while flag:
    for m in (3, 5, 7):
        if not flag:
            break
        for i in range(l, r):
            y = int(n[i])+m*10**x
            if y > N:
                flag = False
                break
            n.append(str(y))

    l = r
    r = len(n)   
    x += 1

res = 0
for s in n:
    if "3" in s and "5" in s and "7" in s:
        res += 1

print(res)

Submission status: Accepted

Solution code:
n=input()
p=""
for i in range(len(n)):
	if int(n[i])>7:
		p+="3"*(len(n)-i)
		break
	elif int(n[i])==7:
		p+="3"
	elif int(n[i])==6:
		p+="2"
		p+="3"*(len(n)-i-1)
		break
	elif int(n[i])==5:
		p+="2"
	elif int(n[i])==4:
		p+="1"
		p+="3"*(len(n)-i-1)
		break
	elif int(n[i])==3:
		p+="1"
	else:
		p+="0"
total=0
for i in range(len(n)):
	total+=int(p[-i-1])*(4**i)
def tet(x):
	q=""
	while x!=0:
		q+=str(x%4)
		x//=4
	if len(q)==0:
		q="0"
	return q[::-1]
ans=[]
cnt=0
for i in range(total):
	if tet(i+1).count("0")==0:
		ans.append(tet(i+1))
for i in range(len(ans)):
	if ans[i].count("1") and ans[i].count("2")\
	and ans[i].count("3"):
		cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
num = (3, 5, 7)
list_357 = ["3", "5", "7"]
list_357_tmp = []
list_753 = []
for i in range(8):
    for j in num:
        for k in list_357:
            list_357_tmp.append(str(j) + k)
    list_357.extend(list_357_tmp)
    list_357_tmp.clear()
for i in list_357:
    if "3" in i and "5" in i and "7" in i:
        list_753.append(int(i))
list_753=set(sorted(list_753))
list_753=sorted(list_753)
N = int(input())
ans = 0
for i in range(len(list_753)):
    if N < list_753[i]:
        ans = i
        break
    elif i == len(list_753)-1:
        ans = i+1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
def sgs(digit):
  ans = []
  if digit == 1:
    return ["7", "5", "3"]
  else:
    sgs_pre = sgs(digit - 1)
    for str in sgs_pre:
      ans.append(str + "7")
      ans.append(str + "5")
      ans.append(str + "3")
    else:
      return ans
digit = len(str(n))
counter = 0
for i in range(3, digit+1):
  for num in sgs(i):
    if "7" in num and "5" in num and "3" in num:
      if int(num) <= n:
        counter += 1
print(counter)

Submission status: Accepted

Solution code:
#総数少ないのでしらみつぶしできる
n = int(input())
#再帰なし版
su753 = set([0])
#リスト内包表記にif
#集合和演算
for _ in range(10):
    tmp = set()
    for x in su753:
        tmp |= set(x*10+y for y in [3,5,7])
    su753 |= tmp 

st = set(str(x) for x in su753 if x<=n)
st = set(x for x in st if set(x)==set('357'))
print(len(st))

Submission status: Accepted

Solution code:
#editorial写経
#総数少ないのでしらみつぶしできる
n = int(input())
###小さい数から開始
def f(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 += f(s+c)
    return ret
        
print(f('0'))

Submission status: Accepted

Solution code:
def dfs(n,num):
	if int(num) > n:
		return 0
	ret = ("3" in num and "5" in num and "7" in num)
	for i in "357":
		ret += dfs(n,num + i)
	return ret

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

Submission status: Accepted

Solution code:
# 753数の列挙
# DFS
def make_753number(n):
    s = str(n)
    if '7' in s and '5' in s and '3' in s:
        n753.add(n)
    if n <= 10**9:
        make_753number(10 * n + 7)
        make_753number(10 * n + 5)
        make_753number(10 * n + 3)


n753 = set()
make_753number(0)
N = int(input())
print(len([1 for n in n753 if n <= N]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

ans = 0
stack = ['7', '5', '3']
while len(stack) != 0:
    nums = stack.pop()
    if int(nums) > N:
        pass

    else:
        if all([nums.count(c) > 0 for c in '753']):
            ans += 1

        for c in '753':
            stack.append(nums + c)



print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()

ret = 0
for l in range(1, len(str(n)) + 1):
    for i in product(*[('3', '5', '7') for _ in range(l)]):
        num = ''.join(i)
        if '3' not in num or '5' not in num or '7' not in num or int(num) > n:
            continue
        ret += 1


print(ret)

Submission status: Accepted

Solution code:
n=int(input())
def count(num):
    total=0
    if int(num)>n:
        return 0
    if ("3" in num and "5" in num and "7" in num):
        total+=1
        #print(num)
    for i in "357":
        total+=count(num+i)
    return total
print(count("0"))

Submission status: Accepted

Solution code:
import math
N = int(input())
if N < 357:
    print(0)
else:
    k = 1
    ans = 0
    while(10**k < N):
        k += 1
    
    nums=set()
    for i in range(1,4**k):
      num=0
      flag=[False,False,False,False]
      for j in range(k):
        tmp= (i // (4**j))%4
       
        if flag[3] and tmp<3:
          flag[tmp-1]=False
            
          break
        else:
          flag[tmp-1]=True
          
        if tmp==1:
          num+=3*(10**j)
        elif tmp==2:
          num+=5*(10**j)
        elif tmp==3:
          num+=7*(10**j)
        else:
          if j<3:
            break    
      
      #print(num,flag)
      for i in range(3):
        if flag[i]:
          if i == 2 and num<=N:
            nums.add(num)
        else:
          break
    forbidden=set()
    for x in nums:
      x=str(x)
      if "0" in x:
        forbidden.add(x)
    print(len(nums)-len(forbidden))

Submission status: Accepted

Solution code:
import itertools
import bisect

tfs = ['3', '5', '7']
lst = list()
for i in range(3, 10):
    lst += itertools.product(tfs, repeat=i)
lst = sorted([int(''.join(z)) for z in filter(lambda x: all([(y in x) for y in tfs]), lst)])
n = int(input())
print(bisect.bisect(lst, n))

Submission status: Accepted

Solution code:
n = int(input())
def sss(a):
    if int(a) > n:
        return 0
    ans = 1 if all(a.count(i) > 0 for i in "753") else 0
    for i in "753":
        ans += sss(a+i)
    return ans
print(sss("0"))

Submission status: Accepted

Solution code:
# editorial
N = int(input())

#from functools import lru_cache
#@lru_cache(maxsize=1000)
def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if  all(s.count(c) for c in "753") else 0
    for c in "753": #文字列数値をforで回すときの書き方！ 覚える
        ret += dfs(s+c) #pythonなのでそのまま+できる
    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
# editorial
N = int(input())

from functools import lru_cache
@lru_cache(maxsize=1000)
def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if  all(s.count(c) for c in "753") else 0
    for c in "753": #文字列数値をforで回すときの書き方！ 覚える
        ret += dfs(s+c) #pythonなのでそのまま+できる
    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
from functools import reduce
n = int(input())

ans = 0
def dfs(numl):
    global ans
    if 3 in numl and 5 in numl and 7 in numl and n >= reduce( lambda a,b:10*a+b, numl):
        ans += 1
    if len(str(n)) > len(numl):
        for i in [3,5,7]:
            dfs(numl+[i])

dfs([])
print(ans)

Submission status: Accepted

Solution code:
def next_rank_num(nStr):
  if nStr == '3':
    return '5'
  elif nStr == '5':
    return '7'
  elif nStr == '7':
    return '3'

def next_num(nStr):
  length = len(nStr)
  i = 1
  nrn = '3'
  nList = []
  while i <= length and nrn == '3':
    nrn = next_rank_num(nStr[length-i])
    nList.append(nrn)
    if nrn == '3':
      i += 1
  nList.reverse()
  if i > length:
    return '3' + ''.join(nList)
  else:
    return nStr[0:length-i] + ''.join(nList)
   
num = int(input())
count = 0
nStr = "357";
while int(nStr) <= num:
  if len({'3', '5', '7'} - set(nStr)) == 0:
    count += 1
  nStr = next_num(nStr)
print(str(count))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2000)

n = int(input())

def dfs(is3, is5, is7, s):
    if s != "" and int(s) > n:
        return 0
    else:
        ans = 0
        if is3 and is5 and is7:
            ans += 1
        ans += dfs(True, is5, is7, s + "3")
        ans += dfs(is3, True, is7, s + "5")
        ans += dfs(is3, is5, True, s + "7")
    return ans

print(dfs(False,False,False,""))

Submission status: Accepted

Solution code:
import itertools

N = input()

element= [3,5,7]

nums = []

for i in range(3,len(N) + 1):
  num = itertools.product(element, repeat = i)
  for j in num:
    if len(set(j)) == 3:
      nums.append(j)

con = 0

numlist = []

for i in range(0,len(nums)):
  S = ""
  for j in range(0,len(nums[i])):
    S += str(nums[i][j])
  S = int(S)
  numlist.append(S)
  
print(len([i for i in numlist if i <= int(N)]))

Submission status: Accepted

Solution code:
n=int(input())
cnt=0 
dp=[[[0 for j in range(10)]for i in range(10)]for k in range(10)]
ans=[0]
arr=[0]
vis=set()
vis.add(0)
while arr: 
    t=arr.pop(0)
    a=t*10+3 
    b=t*10+5 
    c=t*10+7 
    def ok(x):
        return x<=n and x not in vis 
    for i in [a,b,c]:
        if ok(i):
            vis.add(i)
            ans.append(i)
            arr.append(i)
ans.sort()
from bisect import bisect_left as bl 
c=0 
def valid(a):
    one=0 
    two=0 
    three=0 
    while a: 
        if a%10==3:
            one+=1 
        if a%10==5:
            two+=1 
        if a%10==7:
            three+=1 
        a//=10 
    if one==0 or two==0 or three==0:
        return 0 
    return 1 
for i in ans: 
    if valid(i):
        c+=1 
    if i>n:
        break 
print(c)

Submission status: Accepted

Solution code:
# 2019-11-11 16:07:35(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

shichigosan = '357'

def main():

    n = int(sys.stdin.readline().rstrip())
    
    count = 0
    for i in range(3, len(str(n)) + 1):
        sub_shichigosan = list(''.join(s) for s in itertools.product(shichigosan, repeat=i))
        for sub in sub_shichigosan:
            for d in shichigosan:
                if d in sub:
                    continue
                else:
                    break
            else:
                if 357 <= int(sub) <= n:
                    count += 1
    
    print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    N_len = len(str(N))
    if N_len < 3:
        return print(0)
    from itertools import product
    ans_set = set()
    for k in range(3, N_len+1):
        ans_set = ans_set.union({s for s in product("753", repeat=k)
                                 if int("".join(s)) <= N and
                                 len(set(s) & set("753")) == 3})
    print(len(ans_set))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    N_len = len(str(N))
    if N_len < 3:
        return print(0)
    from itertools import product
    ans_set = set()
    for k in range(3, min(N_len, 9)+1):
        ans_set = ans_set.union({s for s in product("753", repeat=k)
                                 if int("".join(s)) <= N and
                                 len(set(s) & set("753")) == 3})
    print(len(ans_set))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

li = [7,5,3]

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

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

kazu = 0
point = 0
k = "0"
while int(k) <= n:
    k = Base_10_to_n(kazu,4)
    if k.count("0") > 0:
        kazu += 1
        continue
    k = k.replace("3","7").replace("1","3").replace("2","5")
    if all(k.count(c)>0 for c in "753"):
        if int(k) <= n:
            point += 1
    kazu += 1
print(point)

Submission status: Accepted

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

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

li = [7,5,3]

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

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

kazu = 0
point = 0
k = "0"
while int(k) <= n:
    k = Base_10_to_n(kazu,4)
    k = k.replace("3","7").replace("1","3").replace("2","5")
    if all(k.count(c)>0 for c in "753")and k.count("0") == 0:
        if int(k) <= n:
            point += 1
    kazu += 1
print(point)

Submission status: Accepted

Solution code:
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():
    global n
    n=int(input())
    print(dfs('0'))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
def n(s):
    if int(s) > N:
        return 0
    if '7' in s and '5' in s and '3' in s:
        p = 1
    else:
        p = 0
    p += n(s+'7')
    p += n(s+'5')
    p += n(s+'3')
    return p
print(n('0'))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    def dfs(s):
        if int(s) > N:
            return 0
        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'))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

n = int(input())
c = 0
for i in range(4**9):
  cur = Base_10_to_n(i, 4)
  if '0' in cur:
    continue
  if cur.count('1') == 0 or cur.count('2') == 0 or cur.count('3') == 0:
    continue
  cur = cur.translate(str.maketrans('123', '357'))
  if int(cur) <= n:
    c += 1
print(c)

Submission status: Accepted

Solution code:
from itertools import product

n = input()
m = []
for i in range(3, len(n)+1):
    m += [int(''.join(j)) for j in product(['3','5','7'], repeat=i) if len(set(j)) == 3]

ans = 0
for i in m:
    if i <= int(n):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

def dfs(x):
    if int(x)>n:
        return 0
    else:
        check=True
        for i in "753":
            if x.count(i)==0:
                check=False
        if check:
            ans=1
        else:
            ans=0
    
    for i in "753":
        ans+=dfs(x+i)
    
    return ans

print(dfs("0"))

Submission status: Accepted

Solution code:
import numpy as np
import itertools

N = int(input())
count = 0

X = [[3,5,7]]*9
X = np.array(X)

result = [[] for i in range(9)]


for n in range(9):
    X[n] = X[n] * (10 ** n)

result[0] = [3,5,7]

for n in range(1,9):
    for x in X[n]:
        for r in result[n-1]:
            result[n].append(x+r)

result = list(itertools.chain.from_iterable(result))

for r in result:
    if r < 333:
        pass
    elif r > N:
        pass
    else:
        if ('3' in str(r)) and ('5' in str(r)) and ('7' in str(r)):
            count += 1

print(int(count))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = 0
def f(x):
    global res
    if x <= n:
        l = len(str(x))
        f(3*10**l+x)
        f(5*10**l+x)
        f(7*10**l+x)
        if '3' in str(x) and '5' in str(x) and '7' in str(x):
            res += 1
f(3)
f(5)
f(7)
print(res)

Submission status: Accepted

Solution code:
n = int(input())
cnt = 0

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

sft("0")
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) 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 func(s, cnt):
    if int(s)>N:
        return cnt
    else:
        b=list(s)
        if '7' in b and '5' in b and '3' in b:
            cnt += 1
        for t in "753":
            cnt = func(s+t, cnt)
        return cnt
    
print(func("0", 0))

Submission status: Accepted

Solution code:
Ns = input()
N = int(Ns)
Nl = len(Ns)
ret = 0
def doit(t, f , s, now):
    global ret
    if t + f + s == 0:
        if int(now) <= N:
            ret += 1
        return
    if t > 0:
        doit(t - 1, f, s, now + str(3)) 
    if f > 0:
        doit(t, f - 1, s, now + str(5)) 
    if s > 0:
        doit(t, f, s - 1, now + str(7)) 
    
for seven in range(1, Nl - 1):
    for five in range(1, Nl - seven):
        least = Nl - seven - five
        for three in range(1, least + 1):
            doit(three, five, seven, '')

print(ret)

Submission status: Accepted

Solution code:
Ns = input()
N = int(Ns)
Nl = len(Ns)
ret = []
def doit(t, f , s, now):
    if t + f + s == 0:
        if int(now) <= N:
            ret.append(now)
        return
    if t > 0:
        doit(t - 1, f, s, now + str(3)) 
    if f > 0:
        doit(t, f - 1, s, now + str(5)) 
    if s > 0:
        doit(t, f, s - 1, now + str(7)) 
    
for seven in range(1, Nl - 1):
    for five in range(1, Nl - seven):
        least = Nl - seven - five
        for three in range(1, least + 1):
            doit(three, five, seven, '')

print(len(ret))

Submission status: Accepted

Solution code:
n = int(input())
l = 1
s = {0}
r = []
for i in range(0, 10):
  t = set()
  for a in s:
    for b in [3, 5, 7]:
      t.add(a + (10 ** i) * b)
  r += t
  s = t
#print(sorted(r))
count = 0
for a in r:
  s = str(a)
  if (357 <= a <= n) and '3' in s and '5' in s and '7' in s:
    count += 1
print(count)

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 # s 自体が七五三数なら +1
	for c in '753':
		ret += dfs(s + c)
	return ret
print(dfs('0'))

Submission status: Accepted

Solution code:
S = input()

seed = [3,5,7]
nums = [3,5,7]
next = []

for i in range(8):
    next = nums[:]
    for n in nums:
        for s in seed:
            next.append(n*10+s)
    nums = next[:]
    next = []

cnt = 0
nums = list(set(nums))
for n in nums:
    s = str(n)
    if '3' in s and '7' in s and '5' in s and n <= int(S):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())

import itertools

li=[]

for i in range(3,11):
  for j in itertools.product("357", repeat=i):
    if "3" in j and "5" in j and "7" in j:
      li.append(int("".join(j)))
i=0
while li[i]<=n:
  i+=1
print(i)

Submission status: Accepted

Solution code:
import os, sys, re, math

N = input()

def get_count(s, count):
    z = s.find('*')
    t = s
    for c in '7530':
        if c == '0' and len(t[:z].replace('0', '')) > 0:
            continue
        t = t[:z] + c + t[z + 1:]
        if z < len(s) - 1:
            count = get_count(t, count)
        else:
            if int(t) <= int(N) and t.find('7') >= 0 and t.find('5') >= 0 and t.find('3') >= 0 and t.find('0') <= 0:
                count += 1
    return count

count = get_count('*' * len(N), 0)
print (count)

Submission status: Accepted

Solution code:
def yonsin(X):
    if(int(X/4)):
        return yonsin(int(X/4))+str(X%4)
    return str(X%4)

n = int(input())
i = 0
yon = 0
cnt = 0
while (True):
	i += 1
	yon = yonsin(i)      
	if ('1' in yon and '2' in yon and '3' in yon and '0' not in yon):
		henkan = yon.replace('3','7').replace('2','5').replace('1','3')
		if (int(henkan) > n):
			break
		cnt += 1
print (cnt)

Submission status: Accepted

Solution code:
Ns = input()
N = int(Ns)
Nl = len(Ns)
ret = set()
def doit(t, f , s, now):
    if t + f + s == 0:
        if int(now) <= N:
            ret.add(now)
        return
    if t > 0:
        doit(t - 1, f, s, now + str(3)) 
    if f > 0:
        doit(t, f - 1, s, now + str(5)) 
    if s > 0:
        doit(t, f, s - 1, now + str(7)) 
    
for seven in range(1, Nl - 1):
    for five in range(1, Nl - seven):
        least = Nl - seven - five
        for three in range(1, least + 1):
            doit(three, five, seven, '')

print(len(ret))

Submission status: Accepted

Solution code:
limit = int(input())
seed = [3,5,7]
set357 = set(seed)
def valid(n):
    x_set = set()
    while(n > 0):
        x_set.add(n % 10)
        n //= 10
    return int(x_set == set357)
def f(current):
    ans = valid(current)
    for s in seed:
        temp = (current * 10) + s
        if temp <= limit:
            ans += f(temp)
    return ans

print(f(0))

Submission status: Accepted

Solution code:
n = int(input())
def doit(s):
    if len(s) > 0 and int(s) > n:
        return 0
    ret = 1 if '3' in s and '5' in s and '7' in s else 0
    for d in '357':
        ret += doit(d + s)
    return ret
print(doit(''))

Submission status: Accepted

Solution code:
n = int(input())

def doit(num):
    if num and int(num) > n:
        return 0
    count = all(d in num for d in '735')
    for d in '735':
        count += doit(num + d)
    return count

print(doit(''))

Submission status: Accepted

Solution code:
num=int(input())
def dfs(n):
  if n>num:
    return 0
  else:
    w=str(n)
    if w=="0":
      w=""
    if "3" in w and "7" in w and "5" in w:
      ret=1
    else:
      ret=0
    for i in "357":   
      ret+=dfs(int(i+w))
    return ret
print(dfs(0))

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())
l=["3","5","7"]
q=deque(["3","5","7"])
l1=["3","5","7"]
count=0
while q:
  a=q.popleft()
  for i in l:
    if int(i+a)<=n:
      q.append(i+a)
      l1.append(i+a)
for i in l1:
  if ("3" in i) and ("5" in i) and ("7" in i):
    count+=1
print(count)

Submission status: Accepted

Solution code:
import itertools

N = input()

A = []
nums = [3,5,7]
con = 0

for i in range(3,len(N) + 1):
  A += list(itertools.product(nums,repeat = i))

L = []

for i in range(0,len(A)):
  a = set(list(A[i]))
  if len(a) == 3:
    L.append(A[i])

Slist = []
    
for i in range(0,len(L)):
  S = ""
  for j in range(0,len(L[i])):
    S += str(L[i][j])
  S = int(S)
  Slist.append(S)

print(len([c for c in Slist if c <= int(N)]))

Submission status: Accepted

Solution code:
n = int(input())
nums = "357"

def dfs(s):
    if int(s) > n: return 0
    res = int(all(num in s for num in nums))
    for num in nums:
        res += dfs(s + num)
    return res

print(dfs("0"))

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())
ans=0
start=["0"]
start=deque(start)
while start:
  s=start.popleft()
  if int(s)<=n and "3" in s and "5" in s and "7" in s:ans+=1
  elif int(s)>n:continue
  for i in ["3","5","7"]:
    start.append(s+i)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
n = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
  if int(s) > N:
    return 0
  # s 自体が七五三数なら +1
  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:
def appendedList(arr, val):
    ret = arr.copy()
    ret.append(val)
    return ret

def dfs(cur, target, ret):
    if 0 < len(cur):
        if target < int(''.join(map(str, cur))):
            return 0
    const = 1 if (3 in cur and 5 in cur and 7 in cur) else 0
    ret3 = dfs(appendedList(cur, 3), target, ret)
    ret5 = dfs(appendedList(cur, 5), target, ret)
    ret7 = dfs(appendedList(cur, 7), target, ret)
    return ret + const + ret3 + ret5 + ret7

if __name__ == '__main__':
    N = int(input())
    print(dfs([], N, 0))

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
def to753(k,d):
    res=0
    for j in range(d):
        res+=(3+2*(k%3))*10**j
        k//=3
    return res

def has753(x):
    f3=f5=f7=False
    while x>0:
        f3=f3 or x%10==3
        f5=f5 or x%10==5
        f7=f7 or x%10==7
        x//=10
    return f3 and f5 and f7

N=int(input())

ans=0

fEND=False

for d in range(3,10):
    if fEND:break
    for k in range(3**d):
        x=to753(k,d)
        if x>N:fEND=True;break
        if has753(x):
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)


def dfs(s):
    if s and int(s) > n:
        return 0

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

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

    return res


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

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
import sys
n = int(input())
if n < 357:
  print(0)
  sys.exit()

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:
s=input()
u=int(s)
n=len(s)

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

f=[0 for _ in range(3)]
a=0

for k in range(1,n+1):
  for i in range(3**k):
    d=i
    t=0
    f[0]=f[1]=f[2]=0
    for j in range(k):
      f[d%3]=1
      t+=(2*(d%3)+3)*10**j
      d = d//3
    if f[0]*f[1]*f[2]:
      if t <= u:
        a+=1

print(a)