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
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり整数
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''


N = int(input())

# 最大の753数は777777753
ans = []

for keta in range(3,10):
    for bit in range(3**keta): # 0:3 1:5 2:7

        temp = 0
        check = [False, False, False]
        for k in range(keta):
            where = bit%(3**(k+1))//(3**k)
            temp += (where*2+3)*(10**k)
            check[where] = True
        
        if all(check):
            ans.append(temp)

ans.sort()
idx = bisect.bisect_right(ans, N)
print(idx)

Submission status: Accepted

Solution code:
n = int(input())


def d(s):
    if int(s) > n:
        return 0
    else:
        out = 1 if all(s.count(i) > 0 for i in '753') else 0

        for z in '753':
            out += d(s + z)

        return out


print(d('0'))

Submission status: Accepted

Solution code:
def sigm(nk):
    s=3**3*(3**(nk-2)-1)/(3-1)
    s=s-3*2**3*(2**(nk-2)-1)/(2-1)
    s=s+(nk-2)*3
    return int(s)
    
n=int(input())

if n<357:
    print(0)
else:
    x0=[357,375,537,573,735,753]
    x1=[3,5,7]
    m=0
    nk=len(str(n))
    if nk==3:
        for j in range(6):
            x=x0[j] 
#            print(x)
            if x<=n:
                m=m+1
    else:
        m=sigm(nk-1)
        for i in range(3**nk):
            ii=i
            x=0
            for j in range(nk):
                iii=ii//3
                ir=ii-iii*3
                ii=(ii-ir)//3
                x=x+int(x1[ir])*10**j
            xstr=str(x)
            if xstr.find("3")>=0 and xstr.find("5")>=0 and xstr.find("7")>=0 and n>=x:
                m=m+1                 
    print(m)

Submission status: Accepted

Solution code:
#桁DP
s = input()
n = int(s)
keta = len(s)
# dp[i][j][k][l][smaller][other]
dp = [
    [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
    for _ in range(keta + 1)
]
dp[0][0][0][0][0] = 1
kazu = [0, 3, 5, 7]
for i in range(keta):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                for smaller in range(2):
                    nd = int(s[i])
                    for d in range(10):
                        ni = i + 1
                        nj = j
                        nk = k
                        nl = l
                        nsmaller = smaller
                        if d not in kazu:
                            continue
                        if d == 3:
                            nj = 1
                        if d == 5:
                            nk = 1
                        if d == 7:
                            nl = 1
                        if smaller == 0:
                            if d > nd:
                                continue
                            if d < nd:
                                nsmaller = 1
                        if d == 0:
                            if nj + nk + nl != 0:
                                continue
                        dp[ni][nj][nk][nl][nsmaller] += dp[i][j][k][l][smaller]
print(dp[keta][1][1][1][0] + dp[keta][1][1][1][1])

Submission status: Accepted

Solution code:
from itertools import product
n=int(input())
cnt=0
kazu=[3,5,7]
for j in range(3,10):
    kumiawase = list(product(kazu, repeat=j))
    for kumi in kumiawase:
        suuji=''
        for moji in kumi:
            suuji+=str(moji)
        if '3'  not in suuji:
            continue
        if '5'  not in suuji:
            continue
        if '7'  not in suuji:
            continue
        hantei=int(suuji)
        if hantei <=n:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import product
n=int(input())
ans = 0
for i in range(3,len(str(n))+1):
    for num in product(('3','5','7'),repeat=i):
        if len(set(num)) == 3 and int("".join(num)) <= n:
            ans += 1
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
    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())

check = 0b000
s = [3,5,7]

ans = 0


def rec(now,check):
    global ans

    if now > n :
        return 0

    if check == 0b111:
        ans+=1

    rec(now*10 +3 ,check | (1<<0))
    rec(now*10+5,check | (1<<1))
    rec(now*10+7,check | (1<<2))



rec(0,0b000)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def solve(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 += solve(s + c)

  return ret

print(solve('0'))

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
def words(n):
    if n==1:return "357"
    A=[]
    for i in "357":
        for j in words(n-1):
            A.append(i+j)
    return A


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

cnt=0
for j in range(3,m+1):
    for i in words(j):
        if n>=int(i) and ("3" in i and "5" in i and "7" in i):
            cnt +=1

print(cnt)

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())
R = len(str(n))


def dfs(ans, r, stop):
    if len(str(ans)) == stop:
        if ans <= n:
            if "3" in str(ans) and "5" in str(ans) and "7" in str(ans):
                return 1
            else:
                return 0
        else:
            return 0

    ret = [dfs(ans * 10 + j, r + 1, stop) for j in (3, 5, 7,)]

    return sum(ret)


x = 0
for i in range(3, R+1):
    x += dfs(0, 0, i)

print(x)

Submission status: Accepted

Solution code:
N = int(input())

def ans(s):
    if int(s) > N:##Nより大きかったら終了
        return 0
    else:
        cnt = int(s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0) ##753数であるかどうか
        return ans(s+"3") + ans(s+"5") + ans(s+"7") + cnt ##その数に3,5,7をつけて753数になるものの数
    
print(ans("0"))##最初の状態は空文字ではなく0.一桁で753数になるものはないため

Submission status: Accepted

Solution code:
n = int(input())
cand = list("357")
stk = ["0"]
ans = 0
while stk:
    tmp = stk.pop()
    if len(tmp)==10:
        if 0<int(tmp)<=n and tmp.count("3") and tmp.count("5") and tmp.count("7"):
            ans += 1
    else:
        if int(tmp)==0: stk.append(tmp+"0")
        for i in cand: stk.append(tmp+i)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = '753'

stack = ['']
cnt = 0
while stack:
    t = stack.pop()
    for c in s:
        u = t + c
        if int(u) <= n:
            if '7' in u and '5' in u and '3' in u:
                # print(u)
                cnt += 1
            stack.append(u)
print(cnt)

Submission status: Accepted

Solution code:
import itertools
def main():
    N = int(input())
    if N < 357:
        print(0)
    else:
        digit = 1
        n = N
        while N//10 != 0:
            N //= 10
            digit += 1
        ans = 0
        for i in range(3,digit+1):
            ls = list(itertools.product([3,5,7],repeat=i))
            for j in ls:
                if 3 in j and 5 in j and 7 in j:
                    tmp = 0
                    for k in range(1,len(j)+1):
                        tmp += j[-k]*10**(k-1)
                    if tmp <= n:
                        ans += 1
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools as it
n = int(input())
ans = 0
for i in range(len(str(n))+1):
    for p in it.product('357', repeat=i):
        if set(p) == {'3', '5', '7'} and int(''.join(p)) <= n:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
"""
from itertools import product
n = input()
ans = 0

for i in range(3,len(n)+1):
    for p in product("357",repeat=i):
        if int("".join(list(p))) > int(n): continue
        if p.count("3")*p.count("5")*p.count("7") != 0: ans += 1

print(ans)
"""

n = int(input())

def bfs(x):
    if int(x) > n: return 0
    cnt = 0
    if x.count("3")*x.count("5")*x.count("7") != 0: cnt = 1
    return cnt + bfs(x+"3") + bfs(x+"5") + bfs(x+"7")

print(bfs("0"))

Submission status: Accepted

Solution code:
from itertools import product
n = input()
ans = 0

for i in range(3,len(n)+1):
    for p in product("357",repeat=i):
        if int("".join(list(p))) > int(n): continue
        if p.count("3")*p.count("5")*p.count("7") != 0: ans += 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
N=int(input())
a=0
for i in range(3,10):
    l=list(product([3,5,7],repeat=i))
    for j in l:
        if 3 in j and 5 in j and 7 in j:
            t=0
            for k in range(i):
                t+=j[k]*10**k
            if t<=N:
                a+=1
print(a)

Submission status: Accepted

Solution code:
n = input()
import itertools as it
print(sum(len(set(p))>2 and int(''.join(p))<=int(n) for i in range(len(n)+1) for p in it.product('357',repeat=i)))

Submission status: Accepted

Solution code:
n = int(input())
import itertools as it
ans = 0
for i in range(11):
  for p in it.product(*['357']*i):
    if len(set(p))>2 and int(''.join(p))<=n:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
import itertools as it
ans = 0
for i in range(len(str(n))+1):
  for p in it.product('357',repeat=i):
    if set(p)=={'3','5','7'} and int(''.join(p))<=n:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(input())

def search(n, ans):
    if n > N:
        return ans
    if ('3' in str(n)) and ('5' in str(n)) and ('7' in str(n)):
        ans += 1
    ans = search(int(str(n)+'3'),ans)
    ans = search(int(str(n)+'5'),ans)
    ans = search(int(str(n)+'7'),ans)
    return ans

print(search(0, 0))

Submission status: Accepted

Solution code:
n=input()
def dfs(s):
  if int(s)>int(n):
    return 0
  cnt=1 if all(s.count(i) 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 dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0 
    # c in '753'はc = {7, 5, 3}と見て、それぞれの文字になるのでall(s.count(c))で全てが0より大きければいい
    for c in '753':
        ret += dfs(s + c)
    return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
import itertools
import bisect

n = int(input())
m = len(str(n))
li = []

for i in range(3,m+1):
    li_tmp = list(itertools.product([3,5,7], repeat = i))
    for j in li_tmp:
        if 3 in j and 5 in j and 7 in j:
            a = 0
            for k in range(i):
                a += j[k] * 10**(i-k-1)
            li.append(a)

print(bisect.bisect(li, n))

Submission status: Accepted

Solution code:
from sys import setrecursionlimit

setrecursionlimit(10**6)
def recur(N_:int,limit:int):
    if N_ > limit:
        return 0
    else:
        tmp = str(N_)
        if ("3" in tmp) and ("5" in tmp) and ("7" in tmp):
            N_ *= 10
            return recur(N_ + 3,limit) + recur(N_ + 5,limit) + recur(N_ + 7,limit) + 1
        else:
            N_ *= 10
            return recur(N_ + 3,limit) + recur(N_ + 5,limit) + recur(N_ + 7,limit)


def main():
    N = int(input())
    ans = recur(3,N) + recur(5,N) + recur(7,N)
    print(ans)
    return   

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools

n=input()

c=[]
for i in range(3,len(n)+1):
    c += list(itertools.product([3,5,7], repeat=i))

m=int(n)
ans=0
for i in range(len(c)):
    if 3 in c[i] and 5 in c[i] and 7 in c[i]:
        search=""
        for g in range(len(c[i])):
            search+=str(c[i][g])
        if m>=int(search):
            ans+=1
print(ans)

Submission status: Accepted

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

def dfs(cur, use):
  global counter

  if cur > N:
    return

  if use == 0b111:
    counter += 1

  dfs(cur * 10 + 7, use | 0b001)
  dfs(cur * 10 + 5, use | 0b010)
  dfs(cur * 10 + 3, use | 0b100)

dfs(0, 0b000)
print(counter)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())


cand=[]
def saiki(num,arc):
    if "3" in arc and "5" in arc and "7" in arc:
        cand.append(arc)
    if num==len(str(N)):
        return 0
    else:
        for item in ["3","5","7"]:
            saiki(num+1,arc+[item])
    return 0


saiki(0,[])

ans=0
for item in cand:
    if N>=((int("".join(item)))):
        ans+=1
        
print(ans)

Submission status: Accepted

Solution code:
import itertools as it
n=int(input())
ans=0
for nn in range(3,10):
    l=[ i for i in it.product(['3','5','7'], repeat=nn)]
    for ll in l:
        if int(''.join(ll)) <= n:
            if len(set(ll)) ==3:
                ans+=1

print(ans)

Submission status: Accepted

Solution code:
import itertools

N=int(input())
num=[3,5,7]
dig=10
p=[1]*dig
for i in range(dig-1):
    p[i+1]=p[i]*10
    
ans=0

def check(n):
    strn=str(n)
    for i in range(len(num)):
        if not (str(num[i]) in strn):
            return False
    return True
        
ans=0
flag=1
for d in range(3,dig):#桁数
    if flag==0:
        break
    for pro in itertools.product(num, repeat=d):
        temp=0
        for j in range(d):
            temp+=pro[-1-j]*p[j]
        if temp>N:
            flag=0
            break
        if check(temp):
            ans+=1
        
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
ans = 0

def func(num):
    global ans
    if num > n:
        return 0

    nnn = list(str(num))
    key = Counter(nnn).keys()
    if len(key) == 3:
        if '3' in key:
            if '5' in key:
                if '7' in key:
                    ans += 1

    func(10 * num + 3)
    func(10 * num + 5)
    func(10 * num + 7)

func(0)
print(ans)

Submission status: Accepted

Solution code:
#114c
import math

N = int(input())

#1 以上 N 以下の整数のうち、七五三数 は何個あるでしょうか？
#ここで、七五三数とは以下の条件を満たす正の整数です。
#    十進法で表記したとき、数字 7, 5, 3 が「それぞれ」 1 回以上現れ、これら以外の数字は現れない。

def search_max(under_list,ans):
    next_list = []
    top_multiplication = 10**(int(math.log10(under_list[0]))+1)
    
    for i in [3,5,7]:
        for j in under_list:
            number = i*top_multiplication + j
            
            if N >= number:
                next_list.append(number)
                
                #七五三数かのチェック
                set_number = set((str(number))) 
                if "3" in set_number and "5" in set_number and  "7" in set_number:
                    ans += 1
                    #print(number)
            else:
                #Nを超えたら終了
                return ans
    
    #桁を増やしてさらに探索
    return search_max(next_list,ans)

if N < 357:
    print(0)
else:
    under_list = [3,5,7]
    ans = search_max(under_list,0)
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

m = len(str(n))

from itertools import product
nums = ['3', '7', '5']

ans = 0
for i in range(3, m+1):
   a = list(product(nums, repeat=i))
   b = [int(''.join(list(j))) for j in a if ('3' in j and '5' in j and '7' in j)]
   if (i == m):
      ans += len([k for k in b if k <= n])
   else:
      ans += len(b)

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
n=int(input())
cnt=0
suuji=[3,5,7]
set_s=set(suuji)
kazu=[]
for i in range(len(str(n))+1):
    kumiawase=list(product(suuji, repeat=i))
    for kumi in kumiawase:
        if set(kumi)==set_s and n >=int(''.join(list(map(str,kumi)))):
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 愚直にいくと、3,5,7のみで作れる数を列挙する
# n 桁なら3+3**2+..+3**(n-1)までは確実に作れる
#　最後は3**8 maxまでループ回しても通りそう
s = int(input())
ans = 0
digit = 0
for j in range(10):
    i = j+1
    if s >= 10**i: pass
    else: break
    digit = i+1
if digit == 0: digit += 1
#print(digit)

num = [3,5,7]
flag = [0,0,0]
for dig in range(1,digit+1):
    for i in range(3**dig):
        val = 0
        tmp = i
        for j in range(dig):
            if flag[tmp % 3] == 0: flag[tmp%3] = 1
            val += num[tmp % 3]*(10**j)
            tmp = tmp // 3
        #print(val)
        if val <= s and flag[0]*flag[1]*flag[2] ==1:
            ans += 1
            #print(val)
        flag = [0,0,0]
print(ans)

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

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

def solve(str_num):
    ans = 0
    if int(str_num or 0) <= N:
        if len(Counter(str_num)) == 3:
            ans += 1
        for n in ("3","5","7"):
            ans += solve(str_num+n)
    return ans

print(solve(""))

Submission status: Accepted

Solution code:
n = int(input())
ans = []
count = 0
def dfs(s):

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

Submission status: Accepted

Solution code:
from itertools import product


def main():
    N = int(input())
    result = 0
    numbers = ["3", "5", "7"]
    for i in range(3, len(str(N)) + 1):
        for p in product(numbers, repeat=i):
            flag = True
            tmp = "".join(p)
            for n in numbers:
                if n in tmp:
                    continue
                else:
                    flag = False
            if flag:
                if int(tmp) <= N:
                    result += 1
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# C - 755

def dfs(n,s):
    if int(s)>n:
        return 0
    res=0
    if s.count('7')>0 and s.count('5')>0 and s.count('3')>0:
        res=1
    
    for i in '753':
        res+=dfs(n,s+i)
    return res

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

Submission status: Accepted

Solution code:

#abc114-C:dfs

n=int(input())

def dfs(s):
    #s>nになったら数えない
    if int(s)>n:
        return 0

    #7,5,3がすべて入ってたら1,それ以外は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:
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:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

N = 0
ans = 0
def rec(n):
    global ans
    if n > N:
        return
    m = _collections.defaultdict(int)
    for i in sorted(str(n)):
        m[i] += 1
    if m["3"] > 0 and m["5"] > 0 and m["7"] > 0:
        ans += 1
    rec(n * 10 + 3)
    rec(n * 10 + 5)
    rec(n * 10 + 7)

def main():
    global N
    N = cin.int()
    rec(3)
    rec(5)
    rec(7)
    print(ans)
    return
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s: str) -> int:
    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(n):
    if int(n) > N:
        return 0
    else:
        ret = 1 if all(n.count(c) > 0 for c in '753') else 0
        for c in '753':
            ret += dfs(n + c)
        return ret


print(dfs('0'))

Submission status: Accepted

Solution code:
N = input()

dp = [[[0] * 8 for _ in range(2)] for _ in range(len(N) + 1)]

dp[0][0][0] = 1

for i in range(len(N)):
    for j in range(2):
        D = 9 if j else int(N[i])
        for d in [x for x in [3, 5, 7] if x <= D]:
            if d == 3:
                dp[i + 1][j | (d < D)][1] += dp[i][j][0] + dp[i][j][1]
                dp[i + 1][j | (d < D)][3] += dp[i][j][2] + dp[i][j][3]
                dp[i + 1][j | (d < D)][5] += dp[i][j][4] + dp[i][j][5]
                dp[i + 1][j | (d < D)][7] += dp[i][j][6] + dp[i][j][7]
            elif d == 5:
                dp[i + 1][j | (d < D)][2] += dp[i][j][0] + dp[i][j][2]
                dp[i + 1][j | (d < D)][3] += dp[i][j][1] + dp[i][j][3]
                dp[i + 1][j | (d < D)][6] += dp[i][j][4] + dp[i][j][6]
                dp[i + 1][j | (d < D)][7] += dp[i][j][5] + dp[i][j][7]
            elif d == 7:
                dp[i + 1][j | (d < D)][4] += dp[i][j][0] + dp[i][j][4]
                dp[i + 1][j | (d < D)][5] += dp[i][j][1] + dp[i][j][5]
                dp[i + 1][j | (d < D)][6] += dp[i][j][2] + dp[i][j][6]
                dp[i + 1][j | (d < D)][7] += dp[i][j][3] + dp[i][j][7]
            else:
                raise Exception("Not 3 or 5 or 7")


ans = dp[len(N)][1][7] + dp[len(N)][0][7]

sub = 0
for i in range(3, len(N)):
    sub753 = 3 ** i
    sub75 = 2 ** i
    sub += sub753 - (3 * sub75 - 3)

print(ans + sub)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

N = int(input())

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

print(cnt_753('0'))

Submission status: Accepted

Solution code:
def SGS(X):
    global ans
    global N
    if X != "":
        if int(X) > N :
            return False
    if "7" in X and "5" in X and "3" in X:
        ans += 1
    SGS("3" + X)
    SGS("5" + X)
    SGS("7" + X)
    return(ans)

ans = 0
N = int(input())
print(SGS(""))

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())
sgs=['']
while len(sgs[-1])<=10:
  tmp=[]
  for s in sgs:
    for t in (list('357')+['']):
      tmp.append(t+s)
  sgs+=tmp
  sgs=list(set(sgs))
  sgs.sort()
sgs2=[]
for i in sgs:
  if len(set(list(i)))==3:
    sgs2.append(i)
sgs2.sort()
ans=0
for i in sgs2:
  if int(i)<=n:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
nums = [3, 5, 7]
num_357 = set()

# retrieval
candidates = []
for i in range(3, 10):
    candidates += list(itertools.product(nums, repeat=i))
for c in candidates:
    for n in nums:
        if n not in c:
            break
    else:
        # c contains 3 && 5 && 7
        tmp = 0
        for ind, i in enumerate(c):
            tmp += i * pow(10, ind)
        num_357.add(tmp)

# result
ans = 0
for n_357 in num_357:
    if n_357 <= 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:
N = int(input())


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


print(dfs('0'))

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
strN = str(N)
lenN = len(strN)
num = ['7','5','3']
count = 0
if N < 357:
    print(0)
else:
    for i in range(3,lenN+1):
        for j in product(num,repeat = i):
            num2 = [str(i) for i in j]
            num2 = ''.join(num2)
            if ('7' in num2) and  ('5' in num2) and  ('3' in num2) and int(num2) <= N:
                count += 1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def dfs(start, n, len_n):
    queue = [start]

    cnt = 0
    while queue:
        parent = queue.pop()
        for c in '357':
            cc = parent+c
            if int(cc) <= n and '3' in cc and '5' in cc and '7' in cc:
                cnt += 1
            if  len(cc) < len_n:
                queue.append(cc)
    return cnt

n = input()
len_n = len(n)
n = int(n)
print(dfs('', n, len_n))

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from itertools import permutations

n = ni()

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

print(dfs('0'))

Submission status: Accepted

Solution code:
import itertools

N = int(input())

ans = 0
for d in range(3, 10):
    for p in itertools.product(["3", "5", "7"], repeat=d):
        s = "".join(p)
        if set(s) != {"3", "5", "7"}:
            continue
        if int(s) > N:
            break
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())
cnt = 0
for i in range(3, 10):
    for j in product(["3", "5", "7"], repeat=i):
        if len(set(j)) == 3:
            if int("".join(j)) <= n:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):#数字を文字列にしたｓを調べる
    if int(s) > n: #もし数値のsがnを超えたらストップ
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0#もしsが753数ならretを1に、そうでないなら0にする
    for i in "753":#再帰
        ret += dfs(s+i)#ret = ret + dfs(s+i)にするとわかりやすい
    return ret#retを返す

print(dfs("0"))

Submission status: Accepted

Solution code:
N = input()

L = []
def dfs(s):
  if len(s) > 1 and int(s) >= int(N):
    return
  for c in '357':
    l = s+c
    if int(l) > int(N):
      return
    
    if '3' in l and '5' in l and '7' in l:
      L.append(int(l))
    dfs(l)
  return

dfs('')

print(len(L))

Submission status: Accepted

Solution code:
import itertools
n = list(input())
if len(n) <= 2:
    print(0)
    exit()
list3 = [1,3,9]
list2 = [1,2,4]
count = 0
for i in range(3,len(n)):
    list3.append(list3[-1]*3)
    list2.append(list2[-1]*2)
    count += list3[-1]-3*list2[-1]+3
A = ["3","5","7"]
l = list(itertools.product(A,repeat = len(n)))

for i in l:
    if "3" in i and "5" in i and "7" in i:
        if n >= list(i) :
            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
    for c in '753':
        ret += dfs(s + c)
    return ret


print(dfs('0'))

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    ans=0
    l=['7','5','3']
    for k in range(3,len(str(N))+1):
        for i in range(3**k):
            x=[]
            for j in range(k):
                x+=l[(i//(3**j))%3]
            if '7' in x and '5' in x and '3' in x:
                x=int(''.join(x))
                if x <= N: ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def stgsn(N, maked_num, now_num):
    if now_num != '':
        if int(now_num) > N:
            return

        maked_num.append(now_num)

    stgsn(N, maked_num, now_num + '7')

    stgsn(N, maked_num, now_num + '5')

    stgsn(N, maked_num, now_num + '3')

    return maked_num


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


    maked_num = []
    now_num = ''

    maked_num = stgsn(N, maked_num, now_num)

    ans = [s for s in maked_num if '3' in s and '5' in s and '7' in s]
    print(len(ans))


main()

Submission status: Accepted

Solution code:
import itertools

n = int(input())

li = [3,5,7]
ans = 0
for i in range(1,11):
    for elm in itertools.product(li,repeat=i):
        if not(7 in elm) or not(5 in elm) or not(3 in elm):
            continue
        ttl = 0
        for j in range(len(elm)):
            ttl += elm[j]*(10**j)
        if ttl<=n:
            #print(ttl)
            ans += 1  

print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

li = [3,5,7]
ans = 0
for i in range(1,11):
    for elm in itertools.product(li,repeat=i):
        if not(7 in elm) or not(5 in elm) or not(3 in elm):
            continue
        ttl = 0
        for j in range(len(elm)):
            ttl += elm[j]*(10**j)
        if ttl<=n:
            #print(ttl)
            ans += 1  

print(ans)