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

def dfs(s):
    # 空文字の場合を特別扱い
    if s and int(s) > N:
        return 0
    ret = 1 if all(c in s for c in '753') else 0
    for c in '753':
        ret += dfs(s + c)
    return ret

print(dfs(''))

Submission status: Accepted

Solution code:
def dfs(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 += dfs(s + c)
    return res


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

Submission status: Accepted

Solution code:
import itertools
N = int(input())
l = len(str(N))
ans = 0
if l < 3:
	pass
else:
	S = []
	for k in range(3,l+1):
		S += list(itertools.product(['3', '5', '7'], repeat=k))
	# print(S)
	for i in range(len(S)):
		num = ''
		for t in range(len(S[i])):
			num = num + S[i][t]
		# print(num)
		if '3' in num:
			if '5' in num:
				if '7' in num:
					if int(num) <= N:
						# print(num)
						ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
n = len(str(N))
# 深さ優先で生成
# 3,5,7が含まれること、Nより小さいことをチェックしてカウント
def dfs(cur, st, n):
    if cur==n:
        if int(st)<=N and ('3' in st and'5' in st and'7'  in st):
            # print((('3'and'5'and'7') in st), st)
            return +1
        else:
            return +0
    else:
        ret1 = dfs(cur+1, st+'3', n)
        ret2 = dfs(cur+1, st+'5', n)
        ret3 = dfs(cur+1, st+'7', n)
        return ret1 + ret2 + ret3

s = 0
for i in range(3, n+1):
    s += dfs(0, '', i)
print(s)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = list(map(int,S()))
    l = len(n)
    dp = [[[0 for k in range(16)] for j in range(2)] for i in range(l+1)]
    dp[0][0][0] = 1
    for i in range(l):
        for j in range(2):
            for k in range(9):
                x = 9 if j else n[i]
                for d in range(x+1):
                    if d == 3:
                        f = 1
                    elif d == 5:
                        f = 2
                    elif d == 7:
                        f = 4
                    else:
                        if k == 0 and d == 0:
                            f = 0
                        else:
                            f = 8
                    dp[i+1][j or d < n[i]][k|f] += dp[i][j][k]
    ans = 0
    for i in range(2):
        ans += dp[l][i][7]
    print(ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
import itertools
N = int(input())
cnt = 0

S = ['3', '5', '7']
for i in range(3, len(str(N)) + 1):
    for p in itertools.product(['3', '5', '7'], repeat = i):
        if all(['3' in p, '5' in p, '7' in p]):
            if int(''.join(p)) <= N:
                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:
# coding: utf-8
# Your code here!

N = int(input())
numbers_753 = dict({3: 0, 5: 1, 7: 2})

count = 0
x = 1
while True:
    if x > N:
        break
    
    count_char = [0, 0, 0]
    temp_x = x
    digit = 0
    while True:
        char = temp_x % 10
        temp_x = temp_x // 10
        
        if char in numbers_753:
            count_char[numbers_753[char]] += 1
            digit += 1
        elif digit > 0:
            x += 10 ** digit
            x -= 2
            break
        else:
            break
        
        if temp_x == 0:
            if count_char[0] * count_char[1] * count_char[2] > 0:
                count += 1
            break
    x += 2
        
print(count)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
k = len(str(n))

k753_num = []
def get_k753_num(k, s):
  if k == 0:
    if "7" in s and "5" in s and "3" in s:
      k753_num.append(int(s))
      return True
    else:
      return False
  pata = get_k753_num(k-1, "7" + s)
  patb = get_k753_num(k-1, "5" + s)
  patc = get_k753_num(k-1, "3" + s)
  
def count_k753_num(k):
  if k<3:
    return 0
  else:
    return 3**k - (2**k * 3) + 3

# count up k-1 753 num
count = 0
for i in range(k):
  count += count_k753_num(i)

# add k 753 num
get_k753_num(k, "")
k753_num.sort()
count += bisect.bisect_right(k753_num, n)

print(count)

Submission status: Accepted

Solution code:
import numpy as np

dp = np.zeros([10+1, 2, 8], dtype=int)

# 桁DPで解く
dp[0, 0, 0] = 1
dp[1:, 1, 0] = 1

N = input()
for i in range(len(N)):  # 桁
    for j in range(2):  # less
        v = 9 if j else int(N[i])
        for k in range(8):  # 3,7,5 含むかどうか

            for l in [l for l in (3, 5, 7) if l <= v]:

                j_idx = int(j or l < v)

                if l == 3:
                    k_idx = (k | 1)
                elif l == 5:
                    k_idx = (k | 2)
                else:
                    k_idx = (k | 4)

                dp[i + 1][j_idx][k_idx] += dp[i][j][k]
    # print(dp[i+1])
# print(dp[len(N)][1][7])
# print(dp[len(N)][0][7])
print(dp[len(N), :, 7].sum())

Submission status: Accepted

Solution code:
N = int(input())


def search(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 += search(s + c)
    return ret


print(search('0'))

Submission status: Accepted

Solution code:
n = int(input())

import bisect
l = []
def dfs(num, index):
    if index == 9:
        if (num.find("3") != -1) and (num.find("5") != -1) and (num.find("7") != -1):
            l.append(int(num))
        return 0
        
    if num == "":
        ret0 = dfs(num + "" , index+1)
    ret1 = dfs(num + "3", index+1)
    ret2 = dfs(num + "5", index+1)
    ret3 = dfs(num + "7", index+1)

    return 0

dfs("", 0)

print (bisect.bisect_right(l,n))

Submission status: Accepted

Solution code:
from itertools import product

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

Submission status: Accepted

Solution code:
#解説をみたあとで再帰的にやる
#方針1: 753数をすべて列挙する
#方針2: N以下の753数を数える

#1-1:
#準753数の末尾に3/5/7を追加することで1桁多い準753数を再帰的に生み出す
#
#1-1-1:seminanagosanの先頭の要素をとりだす
#1-1-2:その要素の末尾に3,5,7を追加したものをseminanagosanの末尾に追加
#1-1-3:上記を繰り返す(ここではN<=10**9が保証されているので,取り出した要素が9桁,つまり10**8以上になったところでストップする)

seminanagosan = [3,5,7]

i = 0
while True:
	if seminanagosan[i] >= 10**8:
		break
	else:
		for s in ['3','5','7']:
			seminanagosan.append(int(str(seminanagosan[i])+s))
		i += 1

#2.seminanagosanはすでにソートされているので,seminanagosanのうち本当に753数でありかつN以下のものを数える

N = int(input())
result = 0
for num in seminanagosan:
	if num > N:
		break
	else:
		nums = str(num)
		if '3' in nums and '5' in nums and '7' in nums:
			result += 1
print(result)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
if N <= 356:
  print(0)
else:
  L = ['3','5','7']
  for i in range(len(str(N))-1):
    for j in range(len(L)):
      L.append(L[j]+'3')
      L.append(L[j]+'5')
      L.append(L[j]+'7')
    K = list(set(L))
    ans = 0
  for i in range(len(K)):
    if K[i].count('3') > 0:
      if K[i].count('5') > 0:
        if K[i].count('7') > 0:
          if int(K[i]) <= N:
            ans += 1
  print(ans)

Submission status: Accepted

Solution code:
N = int(input())
def next_str(num):
    #一番下の桁を大きくする
    dic = {"3":"5","5":"7","7":"3"}
    ketaagari = True
    ret_str = ""
    for char in reversed(str(num)):
        if ketaagari:
            ret_str = str(dic[char]) + ret_str
            if char in ("3","5"):
                ketaagari = False
        else:
            ret_str = str(char) + ret_str
    if ketaagari:
        ret_str = "3" + ret_str
            
    return ret_str
now = 3
cnt = 0
while int(next_str(now))<=N:
    if(set(next_str(now)) == {"3","5","7"}):
        cnt+=1
        # print(next_str(now),"yes!")
    now = next_str(now)
print(cnt)

Submission status: Accepted

Solution code:
def dfs(s,flag):
    if s>upbd:
        return 0
    ret =1 if flag==7 else 0
    ret+=dfs(s*10+3,flag|1)    
    ret+=dfs(s*10+5,flag|2)
    ret+=dfs(s*10+7,flag|4)
    return ret

upbd=int(input())
print(dfs(0,0))

Submission status: Accepted

Solution code:
def dfs(s,flag):
    if s>N:
        return 0
    ret =1 if flag==7 else 0
    ret+=dfs(s*10+3,flag|1)    
    ret+=dfs(s*10+5,flag|2)
    ret+=dfs(s*10+7,flag|4)
    return ret

N=int(input())
print(dfs(0,0))

Submission status: Accepted

Solution code:
def main():
    n = input()
    len_n = len(n)
    semi_753_list = ["3", "5", "7"]
    cnt = 1
    while cnt < len_n + 1:
        addition_list_3 = [str753 + "3" for str753 in semi_753_list if len(str753) == cnt]
        addition_list_5 = [str753 + "5" for str753 in semi_753_list if len(str753) == cnt]
        addition_list_7 = [str753 + "7" for str753 in semi_753_list if len(str753) == cnt]
        semi_753_list += addition_list_3 + addition_list_5 + addition_list_7
        cnt += 1

    ans = 0
    for semi_753_num in semi_753_list:
        if "3" in semi_753_num and "5" in semi_753_num and "7" in semi_753_num and int(semi_753_num) <= int(n):
            ans += 1

    print(ans)


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

print(dfs('0'))

Submission status: Accepted

Solution code:
from itertools import*;n=int(input());print(sum(len(set(a))>2and n>=int(''.join(a))for i in range(10)for a in product(*['357']*i)))

Submission status: Accepted

Solution code:
from itertools import*;n=int(input());print(sum(len(set(a))>2and n>=int(''.join(a))for i in range(11)for a in product(*['357']*i)))

Submission status: Accepted

Solution code:
import itertools as it
def chk(s):
    if "7" in s and "5" in s and "3" in s:
        return True
    else:
        return False
N = int(input())
ans = 0
for i in range(3,len(str(N))+1):
    for p in it.product(["7","5","3"], repeat = i):
        string = ""
        for c in p:
            string += c
        num = int(string)
        if chk(string) and num <= N:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
import math
INF = 10**9


def dfs(s):
    if int(s) > N:
        return 0
    elif s.count('3') == 0 or s.count('5') == 0 or s.count('7') == 0:
        return 0 + dfs(s + "3") + dfs(s + "5") + dfs(s + "7")
    else:
        # print(s)
        return 1 + dfs(s + "3") + dfs(s + "5") + dfs(s + "7")


print(dfs("0"))

Submission status: Accepted

Solution code:
import bisect
N = int(input())
seven53 = []
def dfs(s):
    if all(s.count(c) > 0 for c in "753"):
        seven53.append(s)
    if len(s) > 8:
        return
    else:
        for i in "753":
            dfs(s+i)
dfs("")
seven53 = list(map(int, seven53))
seven53.sort()
print(bisect.bisect_right(seven53, N))

Submission status: Accepted

Solution code:
import bisect
N = int(input())
seven53 = []
def dfs(cur, s):
    if all(s.count(c) > 0 for c in "753"):
        seven53.append(s)
    if cur > 8:
        return
    else:
        for i in "753":
            dfs(cur + 1, s+i)
dfs(0, "")
seven53 = list(map(int, seven53))
seven53.sort()
print(bisect.bisect_right(seven53, N))

Submission status: Accepted

Solution code:
from itertools import product

def ans():
  N = int(input())
  cnt = 0
  for i in range(3, 11):
    for p in product(["3", "5", "7"], repeat = i):
      if("3" in p and "5" in p and "7" in p):
        p = int("".join(p))
        if(p <= N):
          cnt += 1
  print(cnt)
ans()

Submission status: Accepted

Solution code:
N = int(input())
nums = [3, 5, 7]

def count(curr):
    if curr > N:
        return 0
    ret = 0
    for i in nums:
        s = int(curr * 10 + i)
        if s <= N:
            ss = str(s)
            if "3" in ss and "5" in ss and "7" in ss:
                ret += 1
            ret += count(s)
    return ret

print(count(0))

Submission status: Accepted

Solution code:
from itertools import*;n=input();print(sum(sum(2<len(set(a))and int("".join(a))<=int(n)for a in product("357",repeat=l))for l in range(len(n)+1)))

Submission status: Accepted

Solution code:
from itertools import*;n=input();print(sum(sum(2<len(set(a))and int("".join(a))<=int(n)for a in product("357",repeat=l))for l in range(len(n)+1)))

Submission status: Accepted

Solution code:
from itertools import*;n=input();c=[0,0,6,36,150,540,1806,5796,18150];print(sum(c[:len(n)-1])+len(list(a for a in product(["3","5","7"],repeat=len(n))if len(set(a))==3 and int("".join(a))<=int(n))))

Submission status: Accepted

Solution code:
import itertools
n=input()
c=[0,0,6,36,150,540,1806,5796,18150]
b=len(list(a for a in itertools.product(["3","5","7"],repeat=len(n))if len(set(a))==3 and int("".join(a))<=int(n)))
print(sum(c[:len(n)-1])+b)

Submission status: Accepted

Solution code:
#dfs#ans
n=int(input())

def dfs(s):
    #end
    if int(s)>n:
        return 0
    
    for c in "753":
        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())
L = len(str(N))

numbers = [int(l) for l in str(N)]
all, seven, five, three, seven_five, seven_three, five_three = 1, 1, 1, 1, 0, 0, 0
for i, l in enumerate(numbers):
    if l >= 7:
        all = all * 3
        seven_five += 1
        seven_three += 1
        five_three += 1
    elif 5 <= l < 7:
        all = all * 2
        seven = 0
        three = 0
        five_three += 1
    elif 3 <= l < 5:
        all = all * 1
        seven = 0
        three = 0


seven_five = 2 ** seven_five - 2
seven_three = 2 ** seven_three - 2
five_three = 2 ** five_three - 2
ans = all - (seven + five + three) + (seven_five + seven_three + five_three)
print(ans, all, seven, five, three, seven_five, seven_three, five_three)
"""

# take2
N = int(input())
L = len(str(N))
if N < 356:
    print(0)
    quit()


def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out


numbers = []
for i in range(1, 4**L+1):
    num = Base_10_to_n(i, 4)
    number = ''
    for j in num:
        if j == '0':
            number += '0'
        elif j == '1':
            number += '3'
        elif j == '2':
            number += '5'
        elif j == '3':
            number += '7'
    numbers.append(int(number))


ans = 0
ans_list = []
for i, v in enumerate(numbers):
    if v <= N:
        if str(v).count('3') >= 1 and str(v).count('5') >= 1 and str(v).count('7') >= 1 and str(v).count('0') == 0:
            ans += 1
            ans_list.append(v)

print(ans)

Submission status: Accepted

Solution code:
def next_step(n: int):
    # 一の位のステップを決定
    d1 = n % 10
    if d1 < 3:  # 0, 1, 2
        step = 3 - d1
    elif d1 == 3:
        step = 2
    elif d1 < 5:  # 4
        step = 5 - d1
    elif d1 == 5:
        step = 2
    elif d1 < 7:  # 6
        step = 7 - d1
    else:  # 7, 8, 9
        step = 13 - d1

    # 10のくらい以上のステップを決定
    loop = 1
    nn = (n + step) // 10
    while nn > 0:
        d = nn % 10
        if d < 3:
            step += (3 - d) * (10 ** loop)
            nn += (3 - d)
        elif 3 < d and d < 5:
            step += (5 - d) * (10 ** loop)
            nn += (5 - d)
        elif 5 < d and d < 7:
            step += (7 - d) * (10 ** loop)
            nn += (7 - d)
        elif 7 < d:
            step += (13 - d) * (10 ** loop)
            nn += (13 - d)
        loop += 1
        nn //= 10

    return step


def q755(N: int) -> int:
    count = 0
    n = 357
    while n <= N:
        s = str(n)
        if not ('0' in s or '1' in s or '2' in s or '4' in s or '6' in s or '8' in s or '9' in s):
            if '3' in s and '5' in s and '7' in s:
                count += 1
        n += next_step(n)

    return count


if __name__ == "__main__":
    N = int(input())
    ans = q755(N)
    print(ans)

Submission status: Accepted

Solution code:
import itertools

N, = (int(x) for x in input().split())

ncount = 0
for n_s in range(3, 10):
    for s_tuple in itertools.product("357", repeat=n_s):
        found = {"3":False, "5":False, "7":False}
        num = 0
        for s in s_tuple:
            num *= 10
            num += int(s)
            found[s] = True
        if False in found.values():
            continue
        if num <= N:
            ncount += 1

print(ncount)

Submission status: Accepted

Solution code:
n=int(input())

def dfs(s):
  if int(s)>n:
    return 0
  cnt=1 if all(s.count(i)>0 for i in '753') else 0
  for j in '753':
    cnt+=dfs(s+j)
  return cnt
  
print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())
def f(x):
  if x!='' and int(x) > N:
    return 0
  n = 0
  if '3' in x and '5' in x and '7' in x:
    n = 1
  for c in '357':
    n += f(x+c)
  return n
print(f(''))

Submission status: Accepted

Solution code:
N=int(input())

def dfs(i,count):
    if i!="":
        if int(i)>N:
            return count
    if "3" in i and "5" in i and "7" in i:
        count+=1
    count=dfs("3"+i,count)
    count=dfs("5"+i,count)
    count=dfs("7"+i,count)
    return count
  
print(dfs("",0))

Submission status: Accepted

Solution code:
class Main:
    def __init__(self):
        self.N = int(input())

    def dfs(self, ret, cur, f1, f2, f3):
        if self.N < cur:
            return ret

        ret += 1 if f1 and f2 and f3 else 0

        ret = self.dfs(ret, cur * 10 + 7, True, f2, f3)
        ret = self.dfs(ret, cur * 10 + 5, f1, True, f3)
        ret = self.dfs(ret, cur * 10 + 3, f1, f2, True)

        return ret

    @staticmethod
    def main():
        main = Main()
        print(main.dfs(0, 0, False, False, False))


Main.main()

Submission status: Accepted

Solution code:
def dfs(ret, cur, f1, f2, f3):
    if N < cur:
        return ret

    ret += 1 if f1 and f2 and f3 else 0

    ret = dfs(ret, cur * 10 + 7, True, f2, f3)
    ret = dfs(ret, cur * 10 + 5, f1, True, f3)
    ret = dfs(ret, cur * 10 + 3, f1, f2, True)

    return ret


N = int(input())

print(dfs(0, 0, False, False, False))

Submission status: Accepted

Solution code:

def solve(N):
    def rec(k = 0, tight = True, flags = {3: False, 5: False, 7: False}, S = []):
        if k == len(N):
            return sum(flags.values()) == 3
        res = 0
        for key in [0, 3, 5, 7]:
            if not tight or key <= int(N[k]):
                flags_temp = flags.copy()
                if key != 0:
                    flags_temp[key] = True
                else:
                    if sum(S) > 0:
                        continue
                res += rec(k + 1, tight and key == int(N[k]), flags_temp, S + [key])
        return res
    return rec()

print(solve(input()))

Submission status: Accepted

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

print(dfs('0'))

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(x, s, f, t):
    if x > N:
        return 0
    else:
        x = str(x)
        return s * f * t + dfs(int(x + '7'), 1, f, t) + dfs(
            int(x + '5'), s, 1, t) + dfs(int(x + '3'), s, f, 1)


print(dfs(0, 0, 0, 0))

Submission status: Accepted

Solution code:
def f(n, f1, f2, f3):
    ret = 0

    def dfs(n, f1, f2, f3):
        if N < n:
            return 0

        nonlocal ret
        ret += 1 if f1 and f2 and f3 else 0

        dfs(n * 10 + 7, True, f2, f3)
        dfs(n * 10 + 5, f1, True, f3)
        dfs(n * 10 + 3, f1, f2, True)

        return ret

    return dfs(n, f1, f2, f3)


N = int(input())

print(f(0, False, False, False))

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=input()
l=len(n)
n=int(n)
ans=0
cnt=0
def fun(num,i):
    global cnt
    if i==l:
        if (num<=n and ("3" in list(str(num))) and ("5" in list(str(num)))
        and ("7" in list(str(num)))):
            cnt+=1
        return
    else:
        if (num<=n and ("3" in list(str(num))) and ("5" in list(str(num)))
        and ("7" in list(str(num)))):
            cnt+=1
        fun(num*10+3,i+1)
        fun(num*10+5,i+1)
        fun(num*10+7,i+1)  
    return
fun(3,1)
fun(5,1)
fun(7,1)
print(cnt)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)
N = int(input())
length = len(str(N)) + 1
result = []


def dfs(now):
    if len(now) <= length and now != "":
        result.append(now)
        if len(now) == length:
            return
    dfs("3" + now)
    dfs("5" + now)
    dfs("7" + now)


dfs("")
ans = 0
result = set(result)
for r in result:
    i = int(r)
    if i <= N and r.count("3") > 0 and r.count("5") > 0 and r.count("7") > 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
ans = 0


def dfs(n, f1, f2, f3):
    if N < n:
        return

    global ans
    ans += 1 if f1 and f2 and f3 else 0

    dfs(n * 10 + 7, True, f2, f3)
    dfs(n * 10 + 5, f1, True, f3)
    dfs(n * 10 + 3, f1, f2, True)


N = int(input())

dfs(0, False, False, False)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = str(N)
def f(s, p, x):
    if len(s) == 0:
        return 1 if x == 7 else 0
    if p:
        return f(s[1:], True, x | 1) + f(s[1:], True, x | 2) + f(s[1:], True, x | 4) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '8' or s[0] == '9':
        return f(s[1:], True, x | 1) + f(s[1:], True, x | 2) + f(s[1:], True, x | 4) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '7':
        return f(s[1:], True, x | 1) + f(s[1:], True, x | 2) + f(s[1:], False, x | 4) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '6':
        return f(s[1:], True, x | 1) + f(s[1:], True, x | 2) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '5':
        return f(s[1:], True, x | 1) + f(s[1:], False, x | 2) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '4':
        return f(s[1:], True, x | 1) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '3':
        return f(s[1:], False, x | 1) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '2' or s[0] == '1':
        return (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '0':
        return 0
ans = f(S, False, 0)
print(ans)

Submission status: Accepted

Solution code:
import itertools
N=int(input())
S=[]
count=0
for i in range(10):
    S+=itertools.product("753",repeat=i)
for s in S:
    if len(set(s))>2 and int("".join(s))<=N:count+=1
print(count)

Submission status: Accepted

Solution code:
ans = 0


def dfs(n, f1, f2, f3):
    if N < n:
        return

    global ans
    ans += 1 if f1 & f2 & f3 else 0

    dfs(n * 10 + 7, True, f2, f3)
    dfs(n * 10 + 5, f1, True, f3)
    dfs(n * 10 + 3, f1, f2, True)


N = int(input())

dfs(0, False, False, False)

print(ans)

Submission status: Accepted

Solution code:
N=int(input())

a=['3','5','7']
l=['3','5','7']
ans=0

def rec():
    for s in l:
        for i in range(3):
            if(len(s+a[i])<=len(str(N))):
                l.append(s+a[i])
            else:
                break

rec()

for s in l:
    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 copy

word = "753"


def dfs(n):
    ret = 0

    num = 0 if not n else int(''.join(n))

    if N < num:
        return ret

    ret += 1 if len(set(''.join(n)) & set(word)) == len(word) else 0

    for c in word:
        tmp = copy.deepcopy(n)
        n.append(c)
        ret += dfs(n)
        n = tmp

    return ret


N = int(input())

print(dfs([]))

Submission status: Accepted

Solution code:
N = int(input())
def n_ary(l,d): # リストl中の文字でd桁までを全列挙
    if d == 1:
        return(l)
    n = len(l)
    ll = n_ary(l,d-1)
    lll = []
    for i in l:
        for j in ll[n*(n**(d-2)-1)//(n-1):]:
            lll.append(i+j)
    return(ll+lll)
k = [i.replace('0','3').replace('1', '5').replace('2','7') for i in n_ary(['0','1','2'],9)]
#print(n_ary(['0','1','2'],3))
print(len([int(i) for i in k if '3' in i and '5' in i and '7' in i and int(i) <= N]))

Submission status: Accepted

Solution code:
N = input()

def r(s):
    me = '3' in s and '5' in s and '7' in s
    if len(s) < len(N):
        return r(s+'3') + r(s+'5') + r(s+'7') + me
    elif s<=N:
        return me
    else:
        return 0

print(r(''))

Submission status: Accepted

Solution code:
N = input()

def r(s):
    me = all(('3' in s, '5' in s, '7' in s))
    if len(s) < len(N):
        return r(s+'3') + r(s+'5') + r(s+'7') + me
    elif s<=N:
        return me
    else:
        return 0

print(r(''))

Submission status: Accepted

Solution code:
def rec(N,k=0,tight=True,prev_0=True,_7=False, _5=False, _3=False):
    if k==len(N):
        if _7==True and _5==True and _3==True:
            return 1
        else:
            return 0  
    x=N[k]
    r=int(x)  
    if r<3 and tight:
        return 0
    #res = dp[k][0]+dp[k][1]
    res=0
    for i in [0,3,5,7]:
        if not prev_0 and i==0:
            continue
        if i==0:
            prev_0 = True
        else:
            prev_0 = False
        next_tight = tight and i==r
        next_3 = _3
        next_5 = _5
        next_7 = _7
        if tight:
            if i>r:
                return res
        if i==3:
            next_3=True
        elif i==5:
            next_5=True
        elif i==7:
            next_7=True
        temp_rec = rec(N,k+1,next_tight,prev_0,next_7,next_5,next_3)
        res+=temp_rec
    return res
N=input()
print(rec(N))

Submission status: Accepted

Solution code:
from itertools import product
N=int(input())
count=0
S=[]
for i in range(10):
    S+=product("357",repeat=i)
for s in S:
    if len(set(s))>2 and int("".join(s))<=N:count+=1
print(count)

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
INF = 10**18

N=ri()
dig = len(str(N))
ans = 0
if N>=357:
    for d in range(3,dig):
        ans += 3**d - 3*(2**d) + 3
    import itertools
    item = [3,5,7]
    for dl in itertools.product(item,repeat=dig):
        if 3 not in dl or 5 not in dl or 7 not in dl:
            continue
        n = 0
        for i in range(dig):
            n += dl[i]*(10**i)
        if N >= n:
            ans += 1

print(ans)

Submission status: Accepted

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

def dfs(s):
	if int(s) > n:
		return 0
	if all(s.count(c) > 0 for c in '357'):
		count = 1
	else:
		count = 0
	count += dfs(s + '3')
	count += dfs(s + '5')
	count += dfs(s + '7')
	return count

print(dfs('0'))

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
result  = 0
for n in range(1, 10):
    for p in product("357", repeat=n): # n個使った
        if len(set(p)) != 3 :
            continue
        elif int(''.join(p))<=N :
            result += 1
            continue
        
print(result)

Submission status: Accepted

Solution code:
from collections import Counter
import itertools
N=input()
L=len(N)
M=int(N)
S=["3","5","7"]
ans=0
for i in range(3,L):
  for item in itertools.product(S,repeat=i):
    c=Counter(item)
    if c["3"]>0 and c["5"]>0 and c["7"]>0:
      ans+=1
t=0
for item in itertools.product(S,repeat=L):
  c=Counter(item)
  if c["3"]>0 and c["5"]>0 and c["7"]>0:
    t=0
    for j in range(L):
      t+=int(item[-j-1])*(10**j)
    if t<=M:
      ans+=1
  if t>M:
    break
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
m = len(str(n))

count = 0
for mm in range(3, m+1):
    for v in itertools.product('357', repeat=mm):
        if len(set(v)) == 3 and int("".join(v)) <= n:
            count += 1

print(count)

Submission status: Accepted

Solution code:
N=int(input())
N_num=len(str(N))
ans=0

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)

for i in range(3,N_num+1):#i桁についての3進数演算
    for j in range(3**i):
        num=Base_10_to_n(j,3).zfill(i).replace('0','3').replace('1','5').replace('2','7')
        if set(list(num))==set(['3','5','7']) and int(num)<=N:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
def n_shichigo(N, M):
    if (not M == '') and (int(M) > int(N)):
        return 0

    if '7' in M and '5' in M and '3' in M:
        x = 1
    else:
        x = 0
    return n_shichigo(N, M+'7') + n_shichigo(N, M+'5') + n_shichigo(N, M+'3') + x

N = input()
print(n_shichigo(N, ''))

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    count = dfs(s + '3') + dfs(s + '5') + dfs(s + '7')
    if '3' in s and '5' in s and '7' in s:
        count += 1
    return count

print(dfs('0'))

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
    for c in '753':
        ret += dfs(s+c)
    return ret


print(dfs('0'))