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 itertools

sys.setrecursionlimit(10**6)

def main():
    N = list(input())
    intN = int(''.join(N))
    lenN = len(N)
    set753 = ['7', '5', '3']
    ans = 0
    for n in range(3, lenN+1):
        tmp = itertools.product(set753, repeat=n)
        product = [x for x in tmp if len(set(x)) == 3]
        for s in product:
            if int(''.join(s)) <= intN:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import heapq

N=int(input())
count=0
que=[3,5,7]
heapq.heapify(que)
ans=[]
while True:
    x=heapq.heappop(que)
    if N>=x:
        count+=1
        ans.append(x)
    else:
        break
    heapq.heappush(que,10*x+3)
    heapq.heappush(que,10*x+5)
    heapq.heappush(que,10*x+7)

count=0
check=["3","5","7"]
for i in ans:
    for j in check:
        if str(i).count(j)==0:
            break
    else:
        count+=1

print(count)

Submission status: Accepted

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

li = [3, 5, 7]

def dfs():
  stack = deque()
  for i in li:
    stack.append(i)
  while stack:
    q = stack.popleft()
    if all(str(l) in str(q) for l in li):
      ans.append(q)
    for k in li:
      if q * 10 + k <= n:
        stack.append(q * 10 + k)
          
ans = []
dfs()
print(len(ans))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
res = 0


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

    def is_ok(L):
        l = "".join(L)
        if int(l) <= n:
            for i in ["7", "5", "3"]:
                if i not in l:
                    return False
            else:
                return True
        else:
            return False

    def dfs(L):
        global res
        if len(L) == len(str(n)):
            return

        for i in ["7", "5", "3"]:
            L.append(i)
            if is_ok(L):
                res += 1
            dfs(L)
            L.pop()

        return res

    print(dfs([]))


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
nums = ['3', '5', '7']
cnt = 0

def dfs(cur, s):
    global cnt
    if len(cur) > 0 and '3' in cur and '5' in cur and '7' in cur:
        cnt += 1
    for c in nums:
        cur.append(c)
        if int(''.join(cur)) > int(s):
            return
        newcur = cur.copy()
        dfs(newcur, s)
        cur.pop()

def main():
    s = S()
    N = len(s)
    cur = []
    dfs(cur, s)
    print(cnt)

main()

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 = 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:
def dfs(s):
    if s != "":
        if int(s) > n:
            return 0
    if len(set(s)) == 3:
        cnt = 1
    else:
        cnt = 0
    for i in "753":
        cnt += dfs(s + i)
    return cnt


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

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:
def dfs(s):
    global cnt
    if s != "":
        if int(s) > n:
            return
    if len(set(s)) == 3:
        cnt += 1
    dfs(s + "3")
    dfs(s + "5")
    dfs(s + "7")


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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

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 行目でのエラーを防ぐため仕方なく

#文字列をどんどん分岐しながら延ばすときにもdfsは使える
#準七五三数を全列挙し、それぞれについて判定

Submission status: Accepted

Solution code:
import itertools
def I(): return int(input())
N = I()
ans = 0
kouho = set()
for i in range(1,10):
    for x in itertools.product('357',repeat=i):
        kouho.add(x)
for x in kouho:
    if len(set(x))==3 and int(''.join(x))<=N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def make_bscg(i, r, s):
    if i == r:
        return [s]
    ans = []
    ans += make_bscg(i+1, r, s+"3")
    ans += make_bscg(i+1, r, s+"5")
    ans += make_bscg(i+1, r, s+"7")
    return ans


def is_753(x):
    s, f, t = x.count("7"), x.count("5"), x.count("3")
    c = s + f + t
    return s >= 1 and f >= 1 and t >= 1 and c == len(x)
    

N = input()
nn = int(N)
broad_scg = [p for i in range(3, len(N)+1) for p in make_bscg(0, i, "")]
ans = 0
for bscg in broad_scg:
    if int(bscg) > nn:
        break
    if is_753(bscg):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools

s = input()
l = len(s)
N = int(s)

ans = 0
for i in range(3, l+1):
    for t in itertools.product("357", repeat = i):   
        if '3' in t and '5' in t and '7' in t and int(''.join(t)) <= N:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
ans = 0
for i in range(1, 10):
  for x in itertools.product("753", repeat=i):
    s= ''.join(x)
    if int(s) > N: continue
    if '3' not in s: continue
    if '5' not in s: continue
    if '7' not in s: continue
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from collections import Counter
n=int(input())
if n<357:
    print(0)
    exit()
i=357
ans=0
while i<=n:
  c=Counter(str(i))
  if '3' in c and '5' in c and '7' in c:
    if c['3']+c['5']+c['7']==len(str(i)):
      ans+=1
  a=list(map(int,list(str(i))))
  a[-1]+=2
  j=-1
  while a[j]>7 and -j<len(a):
    a[j]=3
    a[j-1]+=2
    j-=1
  if a[0]>7:
    a[0]=33
  i=int(''.join(map(str,a)))

print(ans)

Submission status: Accepted

Solution code:
def dfs(i):
    for j in '753':
        y[i]=j
        if i ==0:
            z = y.copy()
            x.append(z)
        else:
            dfs(i-1)

n = input()
ans = 0
y=['']*len(n)
x=[]
for i in range(2,len(n)):
    dfs(i)
for i in x:
    if int(''.join(i))<=int(n) and len(set(list(''.join(i))))==3:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
OD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

N = int(input())
ans = 0
def dfs(i,before):
    global ans
    if all(before.count(i) > 0 for i in '357') and int(before) <= N:
        ans += 1
    if i == 10:
        return
    for s in '357':
        dfs(i + 1,before + s)
for s in '357':
    dfs(1,s)
print(ans)

Submission status: Accepted

Solution code:
def DFS(num):
    if 3<=len(num)<=m:
        if len(set(list(num)))==3:
            A.append(int(num))
    if len(num)<=m:
        for i in ["3","5","7"]:
            DFS(num+i)


n=input()
m=len(n)
A=[]
for i in ["3","5","7"]:
    DFS(i)

cnt=0
for i in A:
    if i<=int(n):
        cnt +=1
print(cnt)

Submission status: Accepted

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

    N = int(input())

    dq = deque([0])
    cnt = 0
    while dq:
        x = dq.popleft()
        if all(c in str(x) for c in '357'):
            cnt += 1
        for k in (3, 5, 7):
            nx = x * 10 + k
            if nx <= N:
                dq.append(nx)
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
like_753 = []


def dfs(x):
    if n < x:
        return 0
    else:
        like_753.append(x)
        dfs(10*x+3)
        dfs(10*x+5)
        dfs(10*x+7)


dfs(3)
dfs(5)
dfs(7)

ls_753 = [x for x in like_753 if len(set(str(x))) == 3]
print(len(ls_753))

Submission status: Accepted

Solution code:
N=int(input())
ans=0
def dfs(cur,use):
    global ans
    if cur>N: return
    if use==0b111:ans+=1
    dfs(cur*10+7,use | 0b001)
    dfs(cur*10+5,use | 0b010)
    dfs(cur*10+3,use | 0b100)

dfs(0,0)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

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

print(bfs('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:
def main():
    l = []
    l.append(list753from(3))
    l.append(list753from(5))
    l.append(list753from(7))
    flatten = lambda x: [z for y in x for z in (flatten(y) if hasattr(y, '__iter__') and not isinstance(y, str) else (y,))]
    l = flatten(l)
    #print(l)
    #print(len(l))
    print(len(list(filter(lambda x: ('3' in str(x)) & ('5' in str(x)) & ('7' in str(x)), l))))

def list753from(n):
    ret = []
    if n>N:
        return ret
    ret.append(n)
    a = list753from(int(str(n)+"3"))
    if a==[]:
        pass
    else:
        ret.append(a)

    a = list753from(int(str(n)+"5"))
    if a==[]:
        pass
    else:
        ret.append(a)

    a = list753from(int(str(n)+"7"))
    if a==[]:
        pass
    else:
        ret.append(a)

    return ret
    #print("-----")
    #print(n)

if __name__ == '__main__':
    N = int(input())
    main()

Submission status: Accepted

Solution code:
import queue
q = queue.Queue()
n = int(input())
cnt = 0
q.put(3)
q.put(5)
q.put(7)
while not q.empty():
    tmp = q.get()
    if tmp <= n:
        if ('3' in str(tmp)) and ('7' in str(tmp)) and ('5' in str(tmp)):
            cnt += 1
        q.put(tmp*10 + 3)
        q.put(tmp*10 + 5)
        q.put(tmp*10 + 7)
    else:
        continue
print(cnt)

Submission status: Accepted

Solution code:

import itertools

n=int(input())

kn=len(str(n))

icnt=0
for kkn in range(3,kn+1):
    for i in itertools.product([3,5,7], repeat=kkn):
        if (3 in i) and (5 in i) and (7 in i):
#            ni=0
#            for ii in i:
#                ni=ni*10+ii
            ni=int("".join(map(str,i)))
#            print("1:",i,ni)
            if ni<=n:
                icnt+=1    
print(icnt)

Submission status: Accepted

Solution code:

import itertools

n=int(input())

kn=len(str(n))

icnt=0
for kkn in range(3,kn+1):
    for i in itertools.product([3,5,7], repeat=kkn):
        if (3 in i) and (5 in i) and (7 in i):
            ni=0
            for ii in i:
                ni=ni*10+ii
#            print("1:",i,ni)
            if ni<=n:
                icnt+=1    
print(icnt)

Submission status: Accepted

Solution code:
from collections import deque

n = int(input())
nums = [3, 5, 7]

d = deque([0])

count = 0
while True:
    if len(d) == 0:
        break
    x = d.popleft()
    if x > n:
        continue
    else:
        if '3' in str(x) and '5' in str(x) and '7' in str(x):
            count += 1
        for num in nums:
            d.append(x * 10 + num)
print(count)

Submission status: Accepted

Solution code:
from collections import deque
N=int(input())
nums=["3","5","7"]
stack=deque(nums)
cnt=0
while stack:
    cand=stack.pop()
    if ('3' in cand) and ('5' in cand) and ('7' in cand):
        cnt+=1
    for c in nums:
        if int(cand+c)<=N:
            stack.append(cand+c)

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())

def dfs(num):
    if int(num)>n:
        return 0
    else:
        if num.count("3")>=1 and num.count("5")>=1 and num.count("7")>=1:
            ans=1
        else:
            ans=0
        
        for i in "753":
            ans=ans+dfs(num+i)
        return ans
        

print(dfs("0"))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

S = ['3', '5', '7']
n = II()
cnt = 0

def dfs(ns, cnt):
    for s in S:
        news = ''.join([ns, s])
        # print(news)
        if eval(news) > n:
            continue
        elif len(set(list(news))) != 3:
            # 3, 5, 7がそろっていない
            cnt = dfs(news, cnt)
        else:
            cnt += 1
            # print('yes', news, cnt)
            cnt = dfs(news, cnt)
    return cnt


def solve():

    ans = dfs('', 0)
    print(ans)



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N=int(input())
ans=0
S=['']
flg=True
while flg:
  _S=[]
  for s in S:
    _S.append('3'+s)
    _S.append('5'+s)
    _S.append('7'+s)
  for _ in _S:
    if '3' in _ and '5' in _ and '7' in _:
      if int(_)<=N:
        ans+=1
      else:
        flg=False
  S=_S[:]
print(ans)

Submission status: Accepted

Solution code:
s=input()

def dfs(i):
    if int(i) > int(s):
        return 0
    res = 1 if all(i.count(c) > 0 for c in ("753")) else 0

    for t in "753":
        res += dfs(i+t)
    
    return res

print(dfs("0"))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product
from bisect import bisect_right
n = int(input())
ns = []
for i in range(9):
    for j in product(["7", "5", "3"], repeat=i + 1):
        ns.append(''.join(j))
ns = sorted([int(i) for i in ns if len(set(i)) == 3])
print(bisect_right(ns, n))

Submission status: Accepted

Solution code:
n=input()
if len(n)<3:
    print(0)
    exit()
dp=[[[[[0]*2 for _ in range(2)]for _ in range(2)] for _ in range(2)] for _ in range(len(n)+1)]
dp[0][0][0][0][0]=1
for i,c in enumerate(n):
  c=int(c)
  for l in range(2):
    for m in range(2):
      for s in range(2):
        for t in range(2):
          for j in [7,5,3]:
            if l==0 and c<j:
              continue
            dp[i+1][l or j<c][m or j==7][s or j==5][t or j==3]+=dp[i][l][m][s][t]
an=[0, 0, 0, 6, 36, 150, 540, 1806, 5796]
if len(n)==3:
  print(dp[-1][1][1][1][1]+dp[-1][0][1][1][1])
else:
  print(dp[-1][1][1][1][1]+dp[-1][0][1][1][1]+sum(an[3:len(n)]))

Submission status: Accepted

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

def solve(N):
    ans = 0
    d = deque([3,5,7])
    n = d.popleft()
    while n<=N:
        if len(set(list(str(n))))==3:
            ans += 1
        for num in [3,5,7]:
            new = int(str(n)+str(num))
            d.append(new)
        n = d.popleft()
    return ans
print(solve(N))

Submission status: Accepted

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

for i in range(3, len(str(N)) + 1):
  for ptn in itertools.product((3, 5, 7), repeat=i):
    if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
        continue
    a = int("".join(list(map(str, ptn))))
    if a <= N:
      ans +=1

print(ans)

Submission status: Accepted

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

print(f('0'))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

## 3進数
'''
N = ii()

shiki = [1]
for i in range(10):
    tmp = shiki[-1]*3
    shiki.append(tmp)

ele = [3, 5, 7]
l = []
for keta in range(3, 10):
    maxx = shiki[keta]
    for i in range(maxx):
        ten = 10**(keta-1)
        tmp = 0
        for j in reversed(range(keta)):
            tmp += ele[i//shiki[j]] * ten
            i %= shiki[j]
            ten //= 10
        l.append(tmp)

cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ['3', '5', '7']):
        cnt += 1
            
print(cnt)
'''

def n_shinsu(k, n):
    bi=''
    while n!=0:
        bi+=str(n%k)
        n=n//k
    return bi[::-1]

N = ii()
maxx = 8
l = []
ele = [3, 5, 7]
for keta in range(3, 10):
    maxx = (maxx+1) * 3 - 1
    for i in range(maxx):
        tmp = n_shinsu(3, i).zfill(keta)
        ten = 1
        num = 0
        for moji in tmp[::-1]:
            num += ele[int(moji)] * ten
            ten *= 10
        l.append(num)

cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ['3', '5', '7']):
        cnt += 1
            
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

## 3進数
'''
N = ii()

shiki = [1]
for i in range(10):
    tmp = shiki[-1]*3
    shiki.append(tmp)

ele = [3, 5, 7]
l = []
for keta in range(3, 10):
    maxx = shiki[keta]
    for i in range(maxx):
        ten = 10**(keta-1)
        tmp = 0
        for j in reversed(range(keta)):
            tmp += ele[i//shiki[j]] * ten
            i %= shiki[j]
            ten //= 10
        l.append(tmp)

cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ['3', '5', '7']):
        cnt += 1
            
print(cnt)
'''

def n_shinsu(k, n):
    bi=''
    while n!=0:
        bi+=str(n%abs(k))
        if k<0:n=-(-n//k)
        else:n=n//k
    return bi[::-1]

N = ii()
maxx = 8
l = []
ele = [3, 5, 7]
for keta in range(3, 10):
    maxx = (maxx+1) * 3 - 1
    for i in range(maxx):
        tmp = n_shinsu(3, i).zfill(keta)
        ten = 1
        num = 0
        for moji in tmp[::-1]:
            num += ele[int(moji)] * ten
            ten *= 10
        l.append(num)

cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ['3', '5', '7']):
        cnt += 1
            
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

## 3進数

N = ii()

shiki = [1]
for i in range(10):
    tmp = shiki[-1]*3
    shiki.append(tmp)

ele = [3, 5, 7]
l = []
for keta in range(3, 10):
    maxx = shiki[keta]
    for i in range(maxx):
        ten = 10**(keta-1)
        tmp = 0
        for j in reversed(range(keta)):
            tmp += ele[i//shiki[j]] * ten
            i %= shiki[j]
            ten //= 10
        l.append(tmp)

cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ['3', '5', '7']):
        cnt += 1
            
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#import itertools #list(accumulate(A))
#from collections import deque

## FlagをもたせたDFS

N = ii()
ele = [3, 5, 7]
l = []

def dfs(num, flag):
    if num > N:
        return 
    if flag == 7:
        l.append(num)
    num *= 10
    for i, e in enumerate(ele):
        dfs(num+e, flag | 1<<i)

dfs(0, 0)
print(len(l))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools #list(accumulate(A))

N = ii()
l = []

for keta in range(3, 10):
    for koho in itertools.product(['3', '5', '7'], repeat=keta):
        l.append(int(''.join(koho)))

l.sort()

ele = ['3', '5', '7']
cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ele):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools #list(accumulate(A))
from collections import deque

N = ii()
ele = [3, 5, 7]
l = []

def dfs(num, flag3, flag5, flag7):
    #print(num, flag3, flag5, flag7)
    if num > N:
        return 
    if flag3 is flag5 is flag7 is True:
        l.append(num)
    num *= 10
    dfs(num+3, True, flag5, flag7)
    dfs(num+5, flag3, True, flag7)
    dfs(num+7, flag3, flag5, True)

dfs(0, False, False, False)
print(len(l))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools #list(accumulate(A))
from collections import deque

N = ii()
que = deque([33, 35, 37, 53, 55, 57, 73, 75, 77])
ele = ['3', '5', '7']

ind = 0
while True:
    num = que[ind] * 10
    que.append(num + 3)
    que.append(num + 5)
    que.append(num + 7)
    if len(str(num)) >= 10:
        break
    ind += 1

ind = bisect.bisect_right(que, N)

ele = ['3', '5', '7']
cnt = 0
for i in range(ind):
    tmp = str(que[i])
    for e in ele:
        if e not in tmp:
            cnt += 1
            break

print(ind - cnt)

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
    global N
    n = int(s)
    if n>N:
        return 0
    ans = 0
    if n>=357 and all(s.count(c) for c in "753"):
        ans = 1
    ans = ans + dfs(s+"7")+dfs(s+"5")+dfs(s+"3")
    return ans

print(dfs("0"))

Submission status: Accepted

Solution code:
n=int(input())
keta=len(str(n))

cnt=0

kouho=set([])

def saiki(x):
    global kouho
    global keta
    if len(x)==keta:
        return 1

    for s in ["3","5","7"]:
        temp=x+s
        kouho.add(temp)
        saiki(temp)

saiki("")

cnt=0
for item in kouho:
    if "3" in item and "5" in item and "7" in item:
        if int(item)<=n:
            cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
a =deque([3,5,7])
s = 0
while  len(a)!=0 :
  b = a.popleft()
  if b<=n:
    a.append(10*b+3)
    a.append(10*b+5)
    a.append(10*b+7)
    if len(set([j for j in str(b)]))==3:
      s += 1
print(s)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
answer = 0
digit = len(str(N))
# 3, 5, 7だけでできた数を列挙
for d in range(3, digit+1):
    for x in itertools.product(['3', '5', '7'], repeat=d):
        if len(set(x)) != 3:
            continue
        y = int(''.join(x))
        if y <= N:
            answer += 1

print(answer)

Submission status: Accepted

Solution code:
s=input()
l=len(s)
n=int(s)
b=[357,375,537,573,753,735]
if l<=3:
    print(sum(1 for j in b if j<=n));exit()
from itertools import product as pr
ans=0
for k in range(3,l+1):
    for i in pr(("7","5","3"),repeat=k):
        if len(set(i))==3:ans+=int(int("".join(i))<=n)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


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

    que = queue.Queue()
    que.put('3')
    que.put('5')
    que.put('7')

    res = 0
    while not que.empty():
        i = que.get()
        if int(i) <= N:
            if ('3' in i) and ('5' in i) and ('7' in i):
                res += 1
            que.put(i + '3')
            que.put(i + '5')
            que.put(i + '7')
        else:
            break

    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def rec(s, n):
    c = 0
    if s == '':
        s = '0'
    if int(s) > n:
        return 0
    if len(set(s)) == 4:
        # print(s)
        c += 1
    for i in '357':
        w = s + i
        c += rec(w, n)
    return c

def main():
    n = int(input().strip())
    print(rec('', n))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
nana=[7,5,3]
def check(x):
    s=str(x)
    d=1 if all(s.count(str(nana[i]))>=1 for i in range(3) ) else 0
    return d

def dfs(x):
    res=0
    if x>n:
        return 0
    if check(x):
        res+=1
    for i in range(3):
        res+=dfs(10*x+nana[i])
    return res
 
print(dfs(0))

Submission status: Accepted

Solution code:
n=int(input())
nana=[7,5,3]
def check(x):
    s=str(x)
    d=1 if all(s.count(str(nana[i]))>=1 for i in range(3) ) else 0
    return (d and x<=n)

def dfs(x):
    res=0
    if x>n:
        return 0
    if check(x):
        res+=1
    for i in range(3):
        res+=dfs(10*x+nana[i])
    return res
 
print(dfs(0))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

answers = []

def plus(length, target):
    if len(target) == length:
        if not (("3" not in target) or ("5" not in target) or ("7" not in target)):
            answers.append(int(target))
            return
    else:
        for i in ["3","5","7"]:
            next = target + i
            plus(length, next)

def main(N):
    for d in range(3,10):
        plus(d, "")
    print(len([a for a in answers if a<=N]))

if __name__ == "__main__":
    N = int(input())
    main(N)

Submission status: Accepted

Solution code:
n=int(input())
def dfs(k,n):
  if k>n:
    return 0
  c=0
  if '3' in str(k) and '5' in str(k) and '7' in str(k):
    c=1
  l=len(str(k))
  return c+dfs(k+3*10**l,n)+dfs(k+5*10**l,n)+dfs(k+7*10**l,n)
print(dfs(3,n)+dfs(5,n)+dfs(7,n))

Submission status: Accepted

Solution code:
# solution

data = int(input())

def asd(nim):
  if int(nim) > data:
    return 0
  ret = 1 if all(nim.count(c) > 0 for c in "753") else 0
  for c in "753":
    ret += asd(nim+c)
  return ret

print(asd("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'))