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 make753(n):
    ns = str(n)
    l = len(ns)* -1
    flg = True
    while flg:
        for i in range(-1, l-1, -1):
            if ns[i] == '3' or ns[i] == '5':
                ii = (i+1)*-1
                n += 10**ii*2
                flg = False
                break
            if ns[i] == '7':
                ii = (i+1)*-1
                n -= 10**ii*4
                flg = False
                continue
    ns = str(n)
    for j in range(len(ns)):
        if not ns[j] == '3':
            break
        if j == len(ns) - 1:
            n = 10*n+3
    return n


def check753(n):
    ns = str(n)
    l = len(ns)
    a = []
    for i in range(l):
        a.append(int(ns[i]))
    a = list(set(a))
    if len(a) == 3:
        return True
    else:
        return False

n = int(input())
a = 333
cnt = 0

while a <= n:
    if check753(a):
        cnt += 1
    a = make753(a)
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
from collections import deque
def main():
    ans = 0
    targets = deque()
    targets.append('3')
    targets.append('5')
    targets.append('7')
    while targets:
        s = targets.popleft()
        if int(s) <= N:
            if '3' in s and '5' in s and '7' in s:
                ans += 1
            targets.append(s+'3')
            targets.append(s+'5')
            targets.append(s+'7')

    print(ans)
main()

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
i = len(str(n))

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

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
q = deque([3,5,7])
res = 0
def chk(s):
    global res
    if min(s.count('3'), s.count('5'), s.count('7')) > 0:
        res += 1
while q:
    now = q.popleft()
    if now > n:
        continue
    chk(str(now))
    for t in ['3', '5', '7']:
        q.append(int(str(now) + t))
print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
num = ['7', '5', '3']
stack = [('', 0)]
ans = 0
check = defaultdict(lambda:True)
while stack:
    m, l = stack.pop()
    for x in num:
        if x not in m:
            break
    else:
        ans += 1
    for x in num:
        if 10 * l + int(x) <= n:
            if check[10*l + int(x)]:
                stack.append((m + x, 10 * l + int(x)))
                check[10*l + int(x)] = False
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
    if int(s) <= n:
        ans = 1 if all(s.count(x) > 0 for x in "357") else 0
        for x in "357":
            ans += dfs(s+x)
    else:
        return 0
    return ans

print(dfs("0"))

Submission status: Accepted

Solution code:
import itertools
from collections import Counter
import bisect
N = int(input())

lst = ['3','5','7']
anslst = []
for i in range(1,10):
    for v in itertools.product(lst,repeat=i):
        x = Counter(str(v))
        if x['7'] >= 1 and x['5'] >= 1 and x['3'] >= 1:
            anslst.append(int(''.join(v)))
anslst.sort()
index = bisect.bisect_right(list(anslst), N)
print(index)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def dfs(a, ans):
    if a > n:
        return ans
    if set(list(str(a))) == rule:
        ans += 1
    for v in [3, 5, 7]:
        a = a * 10 + v
        ans = dfs(a, ans)
        a //= 10
    return ans


n = int(readline())

rule = set(('3', '5', '7'))
ans = 0

print(dfs(0, ans))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
import itertools#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
#ABC145-E
def main():#s(str)以下の非負整数で条件をK桁満たすものの個数
    N=int(input())
    A=(0,3,5,7)
    ans=0
    for x in itertools.product(A, repeat=9):
        num=0
        for i,xi in enumerate(x):
            num+=10**i*xi
        sn=str(num)
        if num>N or "0" in sn:
            continue
        if "3" in sn and "5" in sn and "7" in sn:
            ans+=1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A = []
str = "357"
lim = 11

def dfs(bef, sz):
    if sz + 1 == lim:
        return
    for i in str:
        t = bef + i
        A.append(t)
        dfs(t, sz + 1)

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

    dfs("", 0)

    ans = 0

    for a in A:
        q = False
        w = False
        e = False
        for i in a:
            if i == '3':
                q = True
            elif i == '5':
                w = True
            elif i == '7':
                e = True
        if q and w and e:      
            ai = int(a)
            if ai <= n:
                ans += 1

    print(ans)

main()

Submission status: Accepted

Solution code:
import itertools
n = int(input())
cnt = 0
for i in range(3,len(str(n))+1):
    for v in itertools.product(["3","5","7"], repeat=i):
        if len(set(v))!=3: continue
        x = int("".join(v))
        if n >= x: cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from collections import deque
def bfs(n):
    ans = 0
    queue = deque([3,5,7])

    while queue:
        num = queue.popleft()

        if num > n:
            return ans

        for i in [3,5,7]:
            queue.append(num*10+i)

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


n = int(input())
print(bfs(n))

Submission status: Accepted

Solution code:
def base10toN(num, base):
    converted_string, modstring = "", ""
    currentnum = num
    if not num:
        return '0'
    while currentnum:
        mod = currentnum % base
        currentnum = currentnum // base
        converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string
    return converted_string
n=int(input())
ans=0
for i in range(4**9):
  s=base10toN(i,4)
  a=[]
  for j in range(len(s)):
    a.append(s[j])
  a.reverse()
  for j in range(9-len(s)):
    a.append('0')
  a.reverse()
  count0=0
  count1=0
  count2=0
  for j in range(9):
    if a[j]=='1':
      count0+=1
    if a[j]=='2':
      count1+=1
    if a[j]=='3':
      count2+=1
  if count0==0 or count1==0 or count2==0:
    continue
  b=[]
  for j in range(9):
    if a[j]=='0':
      b.append('0')
    if a[j]=='1':
      b.append('3')
    if a[j]=='2':
      b.append('5')
    if a[j]=='3':
      b.append('7')
  flag=0
  fail=0
  for j in range(9):
    if a[j]!='0':
      flag=1
    if flag==1 and a[j]=='0':
      fail=1
      break
  if fail==1:
    continue
  p=int(''.join(b))
  if p<=n:
    ans+=1
  else:
    break
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
from bisect import bisect_right
A = []
for i in range(3,10):
    for z in product(("3","5","7"),repeat=i):
        C = {"3":0,"5":0,"7":0}
        for j in range(i):
            C[z[j]] += 1
        if C["3"]>0 and C["5"]>0 and C["7"]>0:
            x = int("".join(z))
            A.append(x)
A = sorted(A)
N = int(input())
ind = bisect_right(A,N)
print(ind)

Submission status: Accepted

Solution code:
def resolve():
    from collections import deque

    def checker(n):
        n = str(n)
        OK3 = False
        OK5 = False
        OK7 = False
        for i in n:
            if i == "3":
                OK3 = True
            elif i== "5":
                OK5 = True
            elif i == "7":
                OK7 = True
        if OK3 and OK5 and OK7:
            return True
        else:
            return False

    n = int(input())
    if n < 357:
        print(0)
    else:
        ans = 0
        nxt = [3, 5, 7]
        nxt = deque(nxt)
        OK = True
        while OK:
            a = nxt.popleft()
            if a > n:
                break
            nxt.append(a*10+3)
            nxt.append(a * 10 + 5)
            nxt.append(a * 10 + 7)
            if checker(a):
                ans += 1
        print(ans)
resolve()

Submission status: Accepted

Solution code:
import itertools
N = int(input())
A = [3,5,7]
s = len(str(N))
ALL = []
for keta in range(3,s+1):
  ALL.extend(list(itertools.product(A, repeat=keta)))
#print(ALL)
ans = 0
for num in ALL:
  L = set(num)
  if 3 not in L or 5 not in L or 7 not in L:
    continue
  temp = ""
  for i in num:
    temp += str(i)
  number = int(temp)
  if number <= N:
    #print(number)
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
# from collections import defaultdict, deque
# import math
# import copy
# from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 1000000007

def dfs(n, s):
    if s:
        num = int(s)
        if num > n:
            return 0

    tmp = 0
    if "3" in s and "5" in s and "7" in s:
        # print(s)
        tmp += 1
    tmp += dfs(n, s + "3")
    tmp += dfs(n, s + "5")
    tmp += dfs(n, s + "7")
    return tmp


def solve():
    n = getN()
    ans = dfs(n, "")
    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

Solution code:
n = int(input())
s = [0]
l = []
while s:
    p = s.pop()
    if p > n:
        continue
    l.append(p)
    s.append(p * 10 + 3)
    s.append(p * 10 + 5)
    s.append(p * 10 + 7)
ans = 0
for x in l:
    p = str(x)
    if p.count('3') and p.count('5') and p.count('7'):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
P=0
def f(x):
  global N,P
  if x>N:
    return None
  s=str(x)
  if '7' in s and '5' in s and '3' in s:
    P+=1
  f(x*10+7)
  f(x*10+5)
  f(x*10+3)
f(7)
f(5)
f(3)
print(P)

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    print(dfs('0', n))


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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())

_357 = {'3', '5', '7'}

ans = 0
for r in range(3, len(str(N)) + 1):
    for numbers in product(('3', '5', '7'), repeat=r):
        if set(numbers) == _357 and int(''.join(numbers)) <= N:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
 
n = int(input())
 
tfs = set()
for i in range(3,10):
    tfs |= set(product(['3', '5', '7'], repeat=i))

cnt = 0
for l in tfs:
    if ('3' in l) and ('5' in l) and ('7' in l):
        num = int(''.join(l))
        if num <= n:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())

tfs = set()
for i in range(1,10):
    tfs |= set(product(['3', '5', '7'], repeat=i))

cnt = 0
for l in tfs:
    if ('3' in l) and ('5' in l) and ('7' in l):
        num = int(''.join(l))
        if num <= n:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
d=deque([3,5,7])
# print(d)

ans=0
# dic={}
while d:
    tmp=d.popleft()
    if tmp<=n:
        s=Counter(str(tmp))
        if s["3"] and s["5"] and s["7"]:
            # print(tmp)
            ans+=1
        d.append(tmp*10+3)
        d.append(tmp*10+5)
        d.append(tmp*10+7)

print(ans)

Submission status: Accepted

Solution code:
ls=[]
def rec(n):
    if len(str(n))>9: return
    ls.append(n)
    for i in [3,5,7]: rec(10*n+i)
n=int(input())
rec(0)
cnt=0
for l in ls:
    if l<=n and all(str(l).count(i)>0 for i in "357"): cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter
ls=[]
def rec(n):
    if len(str(n))>9: return
    ls.append(n)
    rec(n*10+3)
    rec(n*10+5)
    rec(n*10+7)
n=int(input())
rec(3)
rec(5)
rec(7)
cnt=0
for l in ls:
    temp=Counter(str(l))
    if l<=n and len(temp.keys())==3:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())

L = len(str(N))

import math
import itertools

ans = 0

for now_L in range(3, L):
    for a in list(itertools.product([3,5,7], repeat=now_L)):
        num = int("".join(map(str, a)))

        if set(a) == set([3,5,7]):
            ans += 1
        
for a in list(itertools.product([3,5,7], repeat=L)):
    num = int("".join(map(str, a)))
    if num > N:
        break

    if set(a) == set([3,5,7]):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())


def dfs(s:str) -> int: 
    #sに目標値以上の値が入ったら再帰を止める
    if int(s) > N:
        return 0

    #リスト内包表記でsが7, 5, 3のすべてを含んでいるか調べている
    #sが7, 5, 3のすべてを含んでいる場合はs自体が条件を満たす
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0

    #引数の後ろに7,5, 3をつける
    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([3, 5, 7])
res = 0
while True:
    v = d.popleft()
    if v > n:
        break
    if len(set(str(v))) == 3:
        res += 1
    d.append(v * 10 + 3)
    d.append(v * 10 + 5)
    d.append(v * 10 + 7)

print(res)

Submission status: Accepted

Solution code:
def dfs(li):
    if int("".join(li)) > N:
        return 0
    cnt = 1 if all(i in li for i in "357") else 0
    for i in "357":
        cnt += dfs(li + [i])
    return cnt


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

Submission status: Accepted

Solution code:
def dfs(li, cnt, digits):
    if len(li) == digits:
        n = int("".join(li))
        if n <= N and all(i in li for i in ("3", "5", "7")):
            cnt += 1
        return cnt
    for i in ("3", "5", "7"):
        cnt = dfs(li + [i], cnt, digits)
    return cnt


N = int(input())
ans = sum(dfs([], 0, i) for i in range(1, len(str(N)) + 1))
print(ans)

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    N = int(input())
    que = deque(["3", "5", "7"])
    ans = 0
    while True:
        i = que.popleft()
        if int(i) > N:
            break
        if "3" in i and "5" in i and "7" in i:
            ans += 1
        que.append(i + "3")
        que.append(i + "5")
        que.append(i + "7")
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import itertools

n = int(input())

must = set(["3", "5", "7"])
count = 0

for i in itertools.product("0357", repeat=10):
    num = int("".join(i))
    set_ = set(list(str(num)))
    if 0 in set_:
        continue
    if set_ != must:
        continue

    if int("".join(i)) <= n:
        # print(int("".join(i)))
        count += 1
    else:
        break
print(count)

Submission status: Accepted

Solution code:
import collections
import sys
sys.setrecursionlimit(10**6)
dd = collections.defaultdict(int)
def dfs(i,n):
    if(i<=n):
        k = [0,0,0]
        for j in range(len(str(i))):
            if(int(str(i)[j])==3):
                k[0]=1
            if(int(str(i)[j])==5):
                k[1]=1
            if(int(str(i)[j])==7):
                k[2]=1
        if 0 not in k:
            dd[i]=1
        dfs(int(str(i)+"3"),n)
        dfs(int(str(i)+"5"),n)
        dfs(int(str(i)+"7"),n)


def main():
    n = int(input())
    res = 0
    a = [3,5,7]
    for i in a:
        dfs(i,n)
    for key in dd.keys():
        res+=1
    print(res)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
lim=len(str(n))
cand=[3,5,7]
ans=[]
while cand:
    i=cand.pop()
    for j in [3,5,7]:
        k=int(str(i)+str(j))
        if k<=n:
            cand.append(k)
            if len(set(str(k)))==3:
                ans.append(k)
print(len(ans))

Submission status: Accepted

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

ans = 0
ls = ['3','5','7']
for x in ls:
    st = deque([])
    flag = False
    st.append((x, flag))
    while st:
        cur, f = st.pop()
        if f:
            ans += 1
        else:
            if '3' in set(list(cur)) and '5' in set(list(cur)) and '7' in set(list(cur)):
                # print(cur)
                f = True
                ans += 1
        for y in ls:
            if int(cur + y) <= N:
                st.append((cur+y, f))
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
n=int(input())
a=[]
for i in range(3,10):
  a+=(list(product('357',repeat=i)))
cnt=0
for i in a:
  if len(set(i))!=3:
    continue
  if int(''.join(list(i)))<=n:
    cnt+=1
  else:break
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

cands = set()

def dfs(n, c3, c5, c7):
    if c3 >= 1 and c5 >= 1 and c7 >= 1:
        cands.add(n)
    if n >= 10 ** 9:
        return
    dfs(n * 10 + 3, c3 + 1, c5, c7)
    dfs(n * 10 + 5, c3, c5 + 1, c7)
    dfs(n * 10 + 7, c3, c5, c7 + 1)

dfs(0, 0, 0, 0)
print(len([c for c in cands if c <= n]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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)

import numpy as np
L = []
for n in range(3, 10):
    for i in range(3**n):
        i3 = Base_10_to_n(i, 3).zfill(n)
        num = ''
        for j in range(n):
            if i3[j] == '0':
                num += '3'
            elif i3[j] == '1':
                num += '5'
            elif i3[j] == '2':
                num += '7'
        if '3' in num and '5' in num and '7' in num:
            L.append(int(num))
L = np.array(L)
#print(L[L<=N])
print(np.count_nonzero(L[L<=N]))

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')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
ans = 0
for l in range(1, 10):
    for b in product('753', repeat=l):
        if len(set(iter(b))) == 3 and int(''.join(b)) <= n:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
B = []
def dfs(A):
  x = int(''.join(A))
  if x <= n:
    if '7' in A and '5' in A and '3' in A:
      B.append(x)
    dfs(A + ['7'])
    dfs(A + ['5'])
    dfs(A + ['3'])

dfs(['0'])
print(len(B))

Submission status: Accepted

Solution code:
N=int(input())
ans=set()
def saiki(A):
    if len(A)>0:
        B="".join(A)
        count=set(A)
        #print(count)
        if eval(B)<=N:
            if len(count)==3:
                ans.add(B)
        else:
            return
    for i in [3,5,7]:
        A.append(str(i))
        saiki(A)
        A.pop()
saiki([])
print(len(ans))

Submission status: Accepted

Solution code:
def f(L,X=[]):
    if L==1:
        return ["3","5","7"]
    else:
        X=f(L-1)
        Y=[]
        for x in X:
            Y+=[x+"3",x+"5",x+"7"]
        return Y
    
N=int(input())
G=[]
for k in range(1,10):
    V=f(k)
    
    for v in V:
        if ("3" in v) and ("5" in v) and ("7" in v):
            G.append(int(v))

T=0
for x in G:
    if x<=N:
        T+=1

print(T)

Submission status: Accepted

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


def dfs(curr_num, e753, list753, n):
    if curr_num > n: return
    if e753 == 7:
        list753.append(curr_num)
    dfs(curr_num*10+7, e753|4, list753, n)
    dfs(curr_num*10+5, e753|2, list753, n)
    dfs(curr_num*10+3, e753|1, list753, n)


def main():
    n = int(input())
    list753 = []
    dfs(0,0,list753,n)
    print(len(list753))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())
n_len = len(str(n))
ans = 0
for i in range(3,n_len):
    ite = product(range(3),repeat=i)
    for it in ite:
        if 0 in it and 1 in it and 2 in it:
            ans += 1


num_d = {0:7,1:5,2:3}
ite = product(range(3),repeat=n_len)
for it in ite:
    if 0 in it and 1 in it and 2 in it:
        curr_num = 0
        for i,j in enumerate(it):
            curr_num += num_d[j]*(10**(n_len-1-i))
        if curr_num <= n: 
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
ns = input()

dp = [ [ [0]*8  for _ in range(2) ] for _ in range(len(ns)) ]
# dp[i][small_or_not][exist 7,5,3 (0~7)]

first = int(ns[0])
if first > 7:
    dp[0][1][4] = 1
    dp[0][1][2] = 1
    dp[0][1][1] = 1
elif first == 7:
    dp[0][0][4] = 1
    dp[0][1][2] = 1
    dp[0][1][1] = 1
elif first > 5:
    dp[0][1][2] = 1
    dp[0][1][1] = 1
elif first == 5:
    dp[0][0][2] = 1
    dp[0][1][1] = 1
elif first > 3:
    dp[0][1][1] = 1
elif first == 3:
    dp[0][0][1] = 1
dp[0][1][0] = 1

for i in range(0, len(ns)-1):
    next_num = int(ns[i+1])
    dp[i+1][1][0] += dp[i][1][0] 
    for e753 in range(8):
        dp[i+1][1][e753 | 4] += dp[i][1][e753] 
        dp[i+1][1][e753 | 2] += dp[i][1][e753] 
        dp[i+1][1][e753 | 1] += dp[i][1][e753] 

        if next_num > 7:
            dp[i+1][1][e753 | 4] += dp[i][0][e753] 
        if next_num > 5:
            dp[i+1][1][e753 | 2] += dp[i][0][e753] 
        if next_num > 3:
            dp[i+1][1][e753 | 1] += dp[i][0][e753]

        if next_num == 7:
            dp[i+1][0][e753 | 4] += dp[i][0][e753] 
        if next_num == 5:
            dp[i+1][0][e753 | 2] += dp[i][0][e753] 
        if next_num == 3:
            dp[i+1][0][e753 | 1] += dp[i][0][e753]

print( dp[-1][0][7] + dp[-1][1][7])

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())
num=[3,5,7]
def dfs(s):
    if s>N:
        return 0
    a=str(s)
    if a.count("3")>=1 and a.count("5")>=1 and a.count("7")>=1:
        ret=1
    else:
        ret=0
    for i in num:
        ret+=dfs(10*s+i)
    return ret
print(dfs(0))

Submission status: Accepted

Solution code:
from itertools import product
from bisect import bisect_right
def main():
    n = int(input())
    n_753 = []
    for i in range(3, 10):
        for s in product(['3', '5', '7'], repeat = i):
            if len(set(s)) != 3:
                continue
            n_753.append(int(''.join(s)))
    n_753.sort()
    print(bisect_right(n_753, n))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

print(ct('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())
lis = ["3","5","7"]
i = 0
while i < 9:
    X = []
    for L in lis:
        if int(L) < 10**(i):
            pass
        else:
            x3 = "".join([L]+["3"])
            X.append(x3)
            x5 = "".join([L]+["5"])
            X.append(x5)
            x7 = "".join([L]+["7"])
            X.append(x7)
    i += 1
    for x in X:
        lis.append(x)
lis2 = []
for A in lis:
    if "3" in A:
        if "5" in A:
            if "7" in A:
                lis2.append(A)
for i in range(len(lis2)):
    lis2[i] = int(lis2[i])
lis2 = sorted(lis2)
ans = 0
for A in lis2:
    if int(A) > n:
        break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque

n = int(input())
L = []
li = ['3', '5', '7']
que = deque(li)
while que:
    num = que.popleft()
    for i in range(3):
        nn = num + li[i]
        L.append(nn)
        if int(nn) < 10 ** 9:
            que.append(nn)
ans = 0
for num in L:
    if int(num) > n:
        break
    elif all(i in num for i in li):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
list_num = [3, 5, 7]
result=[]
def dfs(val):
  if val > n:
    return

  result.append(val)

  for i in list_num:
    dfs(val*10+i)

dfs(0)
count = 0
for i in result:
  str_num = str(i)

  if str_num.count('3') == 0:
    continue
  if str_num.count('5') == 0:
    continue
  if str_num.count('7') == 0:
    continue
  count += 1

print(count)

Submission status: Accepted

Solution code:
N=int(input())
ans=0
for i in range((3**10-1)//2):
 Sui=[0]*9
 for j in range(9):
  if i==0:
   Sui[j]=0
  elif i%3==0:
   Sui[j]=3
   i-=3
  elif i%3==1:
   Sui[j]=5
   i-=1
  else:
   Sui[j]=7
   i-=2
  i=i//3
 if 3 in Sui and 5 in Sui and 7 in Sui:
  b=0
  for j in range(9):
   b+=Sui[j]*(10**j)
  if b<=N:
   ans+=1
print(ans)

Submission status: Accepted

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

N = int(input())
V = [3, 5, 7]

li = []


def rec(curr, use):
    if curr > N:
        return
    if use == 0b111:
        li.append(curr)
    for i, b in enumerate(V):
        rec(curr * 10 + b, use | max(1, i * 2))


rec(0, 0)

print(len(li))

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10**18
mod = 10**9+7

n = list(map(int, list(input())))
def getAns(now , giri, t,f,s):
    if now == len(n):
        if t and f and s:
            return 1
        else:
            return 0
    tmp = n[now]
    ret = 0
    if giri:
        if tmp > 7:
            ret += getAns(now+1, False, t, f, True)
            ret += getAns(now+1, False, t, True, s)
            ret += getAns(now+1, False, True, f, s)
        elif tmp == 7:
            ret += getAns(now+1, giri, t, f, True)
            ret += getAns(now+1, False, True, f, s)
            ret += getAns(now+1, False, t, True, s)
        elif tmp > 5:
            ret += getAns(now + 1, False, True, f, s)
            ret += getAns(now + 1, False, t, True, s)
        elif tmp == 5:
            ret += getAns(now + 1, False, True, f, s)
            ret += getAns(now + 1, giri, t, True, s)
        elif tmp > 3:
            ret += getAns(now + 1, False, True, f, s)
        elif tmp == 3:
            ret += getAns(now + 1, giri, True, f, s)
    else:
        ret+=getAns(now+1, giri, t,f,True)
        ret+=getAns(now+1, giri, t,True,s)
        ret+=getAns(now+1, giri, True, f, s)
    return ret

ans = 0
for i in range(len(n)-1):
    ans += getAns(i+1,False,False,False,False)
print(ans + getAns(0,True,False,False,False))

Submission status: Accepted

Solution code:
def is_753(n):
    n = str(n)
    return(n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1)


n = int(input())


v = [7, 5, 3]
li = []
prev = [7, 5, 3]

for i in range(9):
    tmp = []
    for j in v:
        for k in prev:
            tmp.append(k * 10 + j)
    prev = tmp
    li = li + prev

li = [x for x in li if is_753(x) and x <= n]

print(len(li))

Submission status: Accepted

Solution code:
n = int(input())

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

print(dfs('0'))