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:
def dfs(L):
    global N, ans
    ret = 0
    if all([L.count(i) for i in ["3", "5", "7"]]):
        ret += 1
    for j in ["3", "5", "7"]:
        if int(L + j) <= int(N):
            ret += dfs(L + j)
    return ret

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

Submission status: Accepted

Solution code:
MAX_DIGIT = 9

n = int(input())

def n753():
    q = ['']
    ns = []
    while q:
        n = q.pop()
        for c in ('7', '5', '3'):
            n1 = n + c
            if len(n1) <= MAX_DIGIT:
                q.append(n1)
                ns.append(n1)
    ns = [int(n) for n in ns if len(set(n)) == 3]
    return ns


answer = sum(1 for n1 in n753() if n1 <= n)
print(answer)

Submission status: Accepted

Solution code:
n = int(input())
ans=0
def dfs(A):
    global ans
    
    if A and int(''.join(A)) > n:
        return
    # 七五三がすべてつかわれているか?
    if not (set(A) ^ set('357')):
        ans+=1
    for v in '357':
        A.append(v)
        dfs(A)
        A.pop()
dfs([])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())


def se(x):
    for i in range(3 ** x):
        r = ""
        for _ in range(x):
            r += "753"[i % 3]
            i //= 3
        if "7" in r and "5" in r and "3" in r:
            yield int(r)


ans = 0
for i in range(9):
    for j in se(i + 1):
        if j <= n:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = [int(x) for x in list(input())] # 例："1234" → [0, 1, 2, 3, 4]

def dfs(L):
    global N
    if len(L) == len(N):
        if L <= N and L.count(7) > 0 and L.count(5) > 0 and L.count(3) > 0:
            return 1
        else:
            return 0

    ans = 0
    if len(L) == 0 or L[-1] == 0:
        ans += dfs(L + [0])
    for j in [3, 5, 7]:
        ans += dfs(L + [j])
    return ans

print(dfs([]))

Submission status: Accepted

Solution code:
n = int(input())
def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all( (i in s) for i in '753') else 0
    for i in '753':
        ret += dfs(s+i)
    return ret
print(dfs('0'))

Submission status: Accepted

Solution code:
N = [0] + [int(x) for x in list(input())] # 例："1234" → [0, 1, 2, 3, 4]

def dfs(L, same):
    '''same ... True if L[i] == N[i] for all i = 0, 1, ..., len(L)-1'''
    global N
    if len(L) == len(N):
        if L.count(7) > 0 and L.count(5) > 0 and L.count(3) > 0:
            return 1
        else:
            return 0

    i = len(L) - 1  # Lの右端の桁
    ans = 0
    if same:    # Lの0, 1, .., i桁がNの0, 1, ..., i桁と同じ
        if i == 0:  # L[i]はダミーの0
            next = [0, 3, 5, 7]
        else:
            next = [3, 5, 7]
        for j in next:
            if j < N[i + 1]:
                ans += dfs(L + [j], same = False)
            if j == N[i + 1]:
                ans += dfs(L + [j], same = True)
    else:  # 残りの桁に関わらずLがNより小さいことが確定している
        if L[i] == 0: # L = [0, 0, .., 0]
            next = [0, 3, 5, 7]
        else:
            next = [3, 5, 7]
        for j in next:
            ans += dfs(L + [j], same = False)

    return ans

print(dfs([0], True))

Submission status: Accepted

Solution code:
n = int(input())
count = 0
stack = [0]
def check(n):
  s = str(n)
  if "3" in s and "5" in s and "7" in s:
    return True
  else:
    return False
while len(stack)>0:
  now = stack.pop()
  if check(now) and now <= n:
    count += 1
  if now < n:
    stack.append(now*10+3)
    stack.append(now*10+5)
    stack.append(now*10+7)
print(count)

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------

# s で始まる七五三数
def dfs(s):
    if int(s) > N:
        return 0
    if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
        cnt = 1
    else:
        cnt = 0
    for c in "753":
        cnt += dfs(s + c)
    return cnt
    

# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())

print(dfs("0"))

Submission status: Accepted

Solution code:
import itertools
from collections import deque
N=int(input())
tp=("3","5","7")
#7,5,3が最低一回登場し、それ以外の数字は登場しない
ans=0
for j in itertools.product(tp, repeat=3):#重複組み合わせで検証
    q=deque()
    q.append(''.join(j))
    while(len(q)>0):
        pos=q.popleft()#現在の数字を出す
        #[真のときの値 if 条件式 else 偽のときの値 for 任意の変数名 in イテラブルオブジェクト]
        if int(pos)<=N and all([ True if k in pos else False for k in tp]):#現在の数字が条件を満たすなら
            ans+=1
        if len(pos)<len(str(N)):
            for i in tp:
                q.append(i+pos)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
global cnt
cnt = 0

def dfs(x, use):
    global cnt
    if x > N:
        return
    if use == 7:
        cnt += 1
    dfs(x*10+3, use|0b001)
    dfs(x*10+5, use|0b010)
    dfs(x*10+7, use|0b100)


dfs(0, 0)
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
def DFS(s):
    if int(s)>n:
        return 0
    tmp = 1 if all(s.count(c) for c in '753') else 0
    for c in '753':
        tmp += DFS(s+c)
    return tmp
print(DFS('0'))

Submission status: Accepted

Solution code:
n = input()
dp = [[0]*8 for _ in range(2)]
if int(n[0])==3:
    dp[0][4] = 1
if int(n[0])==5:
    dp[0][2] = 1
if int(n[0])==7:
    dp[0][1] = 1
if int(n[0])>3:
    dp[1][4] = 1
if int(n[0])>5:
    dp[1][2] = 1
if int(n[0])>7:
    dp[1][1] = 1
for i in range(1, len(n)):
    newdp = [[0]*8 for _ in range(2)]
    if n[i]=='3':
        newdp[0][4] = dp[0][4]
        newdp[0][5] = dp[0][1] + dp[0][5]
        newdp[0][6] = dp[0][2] + dp[0][6]
        newdp[0][7] = dp[0][3] + dp[0][7]
    elif n[i]=='5':
        newdp[0][2] = dp[0][2]
        newdp[0][3] = dp[0][1] + dp[0][3]
        newdp[0][6] = dp[0][4] + dp[0][6]
        newdp[0][7] = dp[0][5] + dp[0][7]
    elif n[i]=='7':
        newdp[0][1] = dp[0][1]
        newdp[0][3] = dp[0][2] + dp[0][3]
        newdp[0][5] = dp[0][4] + dp[0][5]
        newdp[0][7] = dp[0][6] + dp[0][7]
    newdp[1][1] = dp[1][1] + dp[0][1]*(int(n[i])>7) + 1
    newdp[1][2] = dp[1][2] + dp[0][2]*(int(n[i])>5) + 1
    newdp[1][4] = dp[1][4] + dp[0][4]*(int(n[i])>3) + 1
    newdp[1][3] = dp[1][1] + dp[1][2] + dp[1][3]*2 + (dp[0][1] + dp[0][3])*(int(n[i])>5) + (dp[0][2] + dp[0][3])*(int(n[i])>7)
    newdp[1][5] = dp[1][1] + dp[1][4] + dp[1][5]*2 + (dp[0][1] + dp[0][5])*(int(n[i])>3) + (dp[0][4] + dp[0][5])*(int(n[i])>7)
    newdp[1][6] = dp[1][2] + dp[1][4] + dp[1][6]*2 + (dp[0][2] + dp[0][6])*(int(n[i])>3) + (dp[0][4] + dp[0][6])*(int(n[i])>5)
    newdp[1][7] = dp[1][3] + dp[1][5] + dp[1][6] + dp[1][7]*3 + (dp[0][3]+ dp[0][7])*(int(n[i])>3) + (dp[0][5]+ dp[0][7])*(int(n[i])>5) + (dp[0][6]+ dp[0][7])*(int(n[i])>7)
    dp = newdp
print(dp[0][7]+dp[1][7])

Submission status: Accepted

Solution code:
from itertools import product

# input
N = int(input())

# check
if N < 357:
    print(0)
else:
    max_dig = len(str(N))
    dig = 3
    sgs_nuns = []
    sgs = {"7", "5", "3"}
    str_join = "".join
    for n in range(3, max_dig + 1):
        sgs_nuns += [
            str_join(n)
            for n in product(["7", "5", "3"], repeat=n)
            if set(str_join(n)) == sgs and int(str_join(n)) <= N
        ]

    cnt = len(sgs_nuns)
    print(cnt)

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())

L=[]
for i in range(3,10):
    L+=list(product("753",repeat=i))

ans = 0
for l in L:
    if len(set(l)) == 3 and int("".join(l)) <= n:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def base10to(n, b):
    if(int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)
def main():
    n = int(input())
    result = 0
    for i in range(1, 3*10**5):
        temp = base10to(i, 4)
        if '0' not in temp and '1' in temp and '2' in temp and '3' in temp:
            temp = temp.replace('3', '7')
            temp = temp.replace('1', '3')
            temp = temp.replace('2', '5')
            if int(temp) <= n:
                #print(temp)
                result += 1
            else:
                break
    print(result)
main()

Submission status: Accepted

Solution code:
#3,5,7の全探索はdfs全探索で求める
#どれか一つを使ってるかどうかはbitで値を持つ

N = int(input())

ans = 0

def dfs(A,use_num):
    global ans
    #Nより大きくなれば終了
    if len(A) > 1:
        if int("".join(map(str, A))) > N:
            return
    if use_num == 0b111:
        ans += 1

    for v in [3,5,7]:
        A.append(v)
        if v == 3:
            dfs(A,use_num | 0b001)
        elif v == 5:
            dfs(A,use_num | 0b010)
        elif v == 7:
            dfs(A,use_num | 0b100)
        A.pop()

dfs([],0b000)

print(ans)

Submission status: Accepted

Solution code:
import itertools
import bisect
n=int(input())
lst=[]
for i in range(3, len(str(n))+1):
  x=list(itertools.product(["3", "5", "7"], repeat=i))
  z=[int("".join(x[j])) for j in range(len(x))]
  lst+=z
ans=[]
for j in range(len(lst)):
  if len(set(str(lst[j])))==3 and lst[j]<=n:
    ans.append(lst[j])
print(len(ans))

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

h = {}
def dfs(n,i,j,k,f):
    if (n,i,j,k,f) in h:
        return h[(n,i,j,k,f)]
    for e in range(11):
        if 10**e>n:
            break
    p = n//(10**(e-1))
    if e==1:
        s = i+j+k
        if s>1:
            return 0
        elif s==1:
            if i==1 and n>=7 or j==1 and n>=5 or k==1 and n>=3:
                return 1
            else:
                return 0
        else:
            if n>=7:
                return 3
            elif n>=5:
                return 2
            elif n>=3:
                return 1
            else:
                return 0
    sm = 0
    x = 10**(e-1)-1
    y = n-p*(10**(e-1))
    if p>7:
        sm += dfs(x,0,j,k,0)
    elif p==7:
        sm += dfs(y,0,j,k,0)
    if p>5:
        sm += dfs(x,i,0,k,0)
    elif p==5:
        sm += dfs(y,i,0,k,0)
    if p>3:
        sm += dfs(x,i,j,0,0)
    elif p==3:
        sm += dfs(y,i,j,0,0)
    if f>0:
        sm += dfs(x,i,j,k,1)
    h[(n,i,j,k,f)] = sm
    #ddprint(f"n {n} i {i} j {j} k {k} ret {sm}")
    return sm

n = inn()
print(dfs(n,1,1,1,1))

Submission status: Accepted

Solution code:
import itertools
import collections
n=int(input())
l=len(str(n))
cnt=0
if l<3:
  print(0)
  exit()
for i in range(3,l+1):
  for k in itertools.product(['7','5','3'],repeat=i):
    j=int(''.join(k))
    k=list(k)
    x=k.count('7')
    y=k.count('5')
    z=k.count('3')
    if all(vv!=0 for vv in [x,y,z]) and j<=n:
      cnt+=1
print(cnt)

Submission status: Accepted

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

from collections import deque

N = int(input())

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

d = deque([])
Order = 3
for _ in range(0,Order):
    d.append(item[0])

cand = []
cand.append("".join(list(d)))

while True:

    if d == deque([]):
        Order += 1
        for _ in range(0,Order):
            d.append(item[0])

    now = d.pop()

    if now == item[0]:
        d.append(item[1])
        while len(d) < Order:
            d.append(item[0])
        cand.append("".join(list(d)))
#        print("".join(list(d)))
    elif now == item[1]:
        d.append(item[2])
        while len(d) < Order:
            d.append(item[0])
        cand.append("".join(list(d)))
#        print("".join(list(d)))
    elif now == item[2]:
        continue

    # 終了条件
    if int("".join(list(d))) > N:
        break

if int(cand[-1]) > N:
    del cand[-1]

cnt = 0
for Num in cand:
    if Num.count("3") != 0 and Num.count("5") != 0 and Num.count("7") != 0:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import itertools

N = input()
dig = len(N)
N = int(N)

# 全探索
# 3^9 <= 20000
A = ['3','5','7']

def count_num(A,n):
  Comb = itertools.product(A, repeat=n)
  cnt = 0
  for X in Comb:
    X = list(X)
    X_num = int(''.join(X))
    if(X_num <= N):
      j3,j5,j7 = 0,0,0
      for x in X:   
        if(x == '3'): j3 = 1
        elif(x == '5'): j5 = 1
        elif(x == '7'): j7 = 1
      if(j3*j5*j7 == 1):
        cnt += 1
  return cnt      

ans = 0
for i in range(3,dig+1):
  ans += count_num(A,i)
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from itertools import product

N = int(input())
dig = len(str(N))
s = ['3','5','7']
d = deque([''.join(x) for x in product(s,repeat=3)])
ans = 0
while d:
    temp = d.popleft()
    if len(temp) > dig:
        break
    else:
        if int(temp) <= N:
            if len(set(temp)) == 3:
                ans += 1
        d.append(''.join(('3',temp)))
        d.append(''.join(('5',temp)))
        d.append(''.join(('7',temp)))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())


def dfs(numbers, appeared):
    global count
    if int(numbers) <= N:
        if appeared[0] and appeared[1] and appeared[2]:
            count += 1

        tmp1 = appeared.copy()
        tmp1[0] = True
        dfs(numbers + "3", tmp1)
        tmp2 = appeared.copy()
        tmp2[1] = True
        dfs(numbers + "5", tmp2)
        tmp3 = appeared.copy()
        tmp3[2] = True
        dfs(numbers + "7", tmp3)


count = 0
dfs("3", [True, False, False])
dfs("5", [False, True, False])
dfs("7", [False, False, True])

print(count)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def func(S, char):
    l = len(char)
    if int(S[0]) in char:
        num = 0
        for c in char:
            if int(c) < int(S[0]): num += 1
        if len(S) == 1: return num + 1
        return num * l ** (len(S) - 1) + func(S[1:], char)
    else:
        num = 0
        for c in char:
            if int(c) < int(S[0]): num += 1
        return num * l ** (len(S) - 1)

def main():
    S = input()
    ans = func(S, [3, 5, 7]) - func(S, [3, 5]) - func(S, [5, 7]) - func(S, [3, 7]) + func(S, [3]) + func(S, [5]) + func(S, [7])
    for i in range(1, len(S)):
        n = len(S) - i
        ans += 3 ** n - 3 * 2 ** n + 3
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
ans=0
from itertools import product
s=[]
for i in range(3,10):
  s+=list(product("357",repeat=i))
for i in range(0,len(s)):
  if "3" in s[i] and "5" in s[i] and "7" in s[i]:
    if n>=int("".join(s[i])):
      ans=ans+1
print(ans)

Submission status: Accepted

Solution code:
import itertools as it
n = int(input())
l = len(str(n))

res = []
for i in range(3, l + 1):
    for gen in it.product("357", repeat=i):
        gen_s = "".join(gen)
        if int(gen_s) <= n:
            res.append(gen_s)

cnt = 0
for r in res:
    if all(r.count(c) for c in "357"):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
lis = [str(3),str(5),str(7)]
nu = [str(3),str(5),str(7)]
for i in range(8):
    nlis = []
    for j in lis:
        for k in nu:
            nlis.append(j+k)
    lis.extend(nlis)
slis = set(lis)
mlis = []
cnt = 0
for i in slis:
    if "3" not in i or "5"  not in i or "7" not in i:
        continue
    if int(i)>n: continue
    cnt+=1
    mlis.append(i)
print(cnt)
#print(slis)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
def dfs(m):
  global ans
  if m > n:
    return
  sm = str(m)
  if "3" in sm and "5" in sm and "7" in sm:
    ans += 1
  dfs(m*10+3)
  dfs(m*10+5)
  dfs(m*10+7)
dfs(0)
print(ans)

Submission status: Accepted

Solution code:
import copy
n = int(input())
ans = 0
for i in range(2,10):
  list = ["3","5","7"]
  for j in range(i):
    dlist = []
    for k in list:
      for l in ("3","5","7"):
        dlist.append(k+l)
    list = copy.copy(dlist)
  for m in list:
    if "3" in m and "5" in m and "7" in m:
      if int(m) <= n:
        ans +=1
      else:
        print(ans)
        exit()

Submission status: Accepted

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

N = int(input())

def check(p):
  return ("3" in p and "5" in p and "7" in p)
  
cnt = 0
def dfs(n):
  if int(n) > N:
    return
  global cnt
  if check(n):
    cnt += 1
  for c in ("3","5","7"):
    dfs(n + c)

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

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
d = deque()
d.append("3")
d.append("5")
d.append("7")
p = ["3","5","7"]
ans = 0
while d:
    now = d.popleft()
    for i in p:
        d.append(now+i)
    if now.count("3")*now.count("5")*now.count("7") > 0 and int(now) <= n:
        ans += 1
    if int(now) > n:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def bfs(N):
    q = deque(["7", "5", "3"])
    res = []

    while q:
        s = q.popleft()

        for c in ["7", "5", "3"]:
            new = s + c

            if int(new) > N:
                continue

            if "7" in new and "5" in new and "3" in new:
                res.append(new)

            q.append(new)

    return len(res)


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

    ans = bfs(N)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())

que=deque([3,5,7])
x=0
ans=0
while True:
    x=que.popleft()
    if x>n:
        break
    s=str(x)
    if s.count('3')>0 and s.count('5')>0 and s.count('7')>0:
        ans+=1
    que.append(10*x+3)
    que.append(10*x+5)
    que.append(10*x+7)
print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
ns = lambda: stdin.readline().rstrip()
na = lambda: list(map(int, stdin.readline().split()))

# code here
N = ni()
ans = 0
def dfs(n):
    global ans
    if n > N:
        return

    if '3' in str(n) and '5' in str(n) and '7' in str(n):
        ans += 1

    dfs(n*10+3)
    dfs(n*10+5)
    dfs(n*10+7)

dfs(0)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = set()
for length in range(3, len(str(N)) + 1):
    for t in range(3 ** length):
        xs = [[3, 5, 7][t // 3**i % 3] for i in range(length)]
        if 3 in xs and 5 in xs and 7 in xs:
            n = int(''.join(map(str, xs)))
            if 1 <= n <= N:
                ans.add(n)
print(len(ans))

Submission status: Accepted

Solution code:
N=int(input())
def main(number):
   if int(number) > N:
      return 0
   ret = 1 if all (number.count(c) > 0 for c in '753') else 0
   for c in "753":
      ret+=main(number+c)
   return ret
print(main("0"))

Submission status: Accepted

Solution code:
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:
n = int(input())
inf = 1001001001
lis = [7, 5, 3]
ans = 0
def dfs(i):
    if i > inf:
        return
    else:
        if i <= n and "7" in str(i) and "5" in str(i) and "3" in str(i):
            global ans
            ans += 1
        for j in lis:
            dfs(10*i + j)
dfs(0)
print(ans)

Submission status: Accepted

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

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:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def dfs(S, N):
    if int(S) > N:
        return 0

    ret = 1 if all(S.count(s) for s in '753') else 0
    for s in '753':
        ret += dfs(S+s, N)
    return ret


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    print(dfs('0', N))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
  if int(s) > N:
    return 0
  count = 1 if all(s.count(x) > 0 for x in ["7","5","3"]) else 0 

  for i in ["7","5","3"]:
    count += dfs(s+i)

  return count


print(dfs("0"))

Submission status: Accepted

Solution code:
N = input()
le = len(N)
N = int(N)
ans = 0
L = ['3', '5', '7']


def clear(n):
    global ans

    if len(n) > le:
        return
    if ('3' in n) and ('5' in n) and ('7' in n) and int(n) <= N:
        ans += 1

    for l in L:
        n = n + l
        clear(n)
        n = n[:-1]


clear('')
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    max_l = len(N) + 1

    s = set()

    def search(i, n, f3, f5, f7):
        if f3 and f5 and f7:
            s.add(n)
        if i < 0:
            return

        i -= 1
        search(i, n * 10 + 3, True, f5, f7)
        search(i, n * 10 + 5, f3, True, f7)
        search(i, n * 10 + 7, f3, f5, True)

    search(max_l, 0, False, False, False)

    count = 0
    for v in s:
        if v <= n:
            count += 1

    print(count)


main()

Submission status: Accepted

Solution code:
n = int(input())
l = [3, 5, 7]
ans = 0

for i in range(26484):
    x = str(l[i])
    l.append(int(x+"3"))
    l.append(int(x+"5"))
    l.append(int(x+"7"))

for i in l:
    if i > n:
        print(ans)
        break
    
    x = str(i)
    if x.count("3")>0 and x.count("5")>0 and x.count("7")>0:
        ans += 1

Submission status: Accepted

Solution code:
import sys
from collections import deque

input = sys.stdin.readline


def bfs(N):
    res = 0
    queue = deque(["3", "5", "7"])
    while queue:
        num = queue.popleft()
        if int(num) > N:
            break
        res += 1 if all(d in num for d in "357") else 0
        queue.append("".join([num, "3"]))
        queue.append("".join([num, "5"]))
        queue.append("".join([num, "7"]))
    return res


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

    ans = bfs(N)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import deque

input = sys.stdin.readline


def bfs(N):
    res = 0
    queue = deque(["3", "5", "7"])
    while queue:
        num = queue.popleft()
        if int(num) > N:
            break
        if all(("3" in num, "5" in num, "7" in num)):
            res += 1
        queue.append("".join([num, "3"]))
        queue.append("".join([num, "5"]))
        queue.append("".join([num, "7"]))
    return res


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

    ans = bfs(N)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque
def solve():
    N = int(input())
    ans = 0
    d = deque([3,5,7])
    while len(d):
        n = d.popleft()
        for i in range(3,8,2):
            a = n*10+i
            if a<=N:
                if len(set(list(str(a))))==3:
                    ans += 1
                d.append(a)
    return ans
print(solve())

Submission status: Accepted

Solution code:
n = int(input())
if n < 3:
    print(0)
    exit()
elif n < 5:
    print(1)
    exit()
elif n < 7:
    print(2)
    exit()
sft = []
tmp = ['33','35','37','53','55','57','73','75','77']
while True:
    a = []
    for j in tmp:
        t = set(j)
        if "5" in t and "7" in t: sft.append(j + "3")
        if "3" in t and "7" in t: sft.append(j + "5")
        if "5" in t and "3" in t: sft.append(j + "7")
        a.append(j + "3")
        a.append(j + "5")
        a.append(j + "7")
    tmp = a

    if int(sft[-1]) > n:
        for i in range(len(sft)):
            if int(sft[i]) > n:
                print(i)
                exit()

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code

def resolve():
    N=input()
    n=len(N)
    N=int(N)
    ans=set()
    numans=0
    stack=[(3,1),(5,2),(7,4)]
    row=(3,5,7)
    while (stack!=[]):
        t,u=stack.pop()
        for n,l in enumerate(row):
            neu=(t*10+l,u|(2**n))
            if neu[0]<=N:
                stack.append(neu)
                if neu[1]==7:
                    ans.add(neu[0])
    print(len(ans))
#%%submit!
resolve()

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
# C - 755
import itertools

N = int(input())
ans = 0

for i in range(10):
    for j in itertools.product(['3','5','7'], repeat = i):
        if j.count('3') > 0 and j.count('5') and j.count('7'):
            if int(''.join(map(str,j))) <= N:
                ans += 1

print(ans)