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
sys.setrecursionlimit(10**7)
n = int(input())
def nana(cur, x):
  if cur == 9:
    if int(x) <= n and set(x) >= {"3", "5", "7"}:
      return 1
    return 0
  return (nana(cur+1, x+"0") if not x or x[-1]=="0" else 0) + nana(cur+1, x+"3") + nana(cur+1, x+"5") + nana(cur+1, x+"7")
print(nana(0, ""))

Submission status: Accepted

Solution code:
N=int(input())
l=len(str(N))

def calc(st):
    st=str(st)
    if(len(st)>l):return 0
    t=calc(st+"3")
    f=calc(st+"5")
    s=calc(st+"7")
    o=0
    if(st.find("7")>=0 and st.find("5")>=0 and st.find("3")>=0 and int(st)<=N):
        o=1
    return (t+f+s+o)

print(calc(str()))

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)

# dp[i][bit][j] := i桁目まで見て、出現済の3,5,7の集合がbitで、Nより小さいのが確定しているorしていない(j=0,1)状態の場合の数
dp = list3d(N+1, 1<<3, 2, 0)
dp[0][0][0] = 1
for i in range(N):
    a = int(S[i])
    for bit in range(1<<3):
        # 0への遷移
        if bit == 0:
            dp[i+1][bit][1] += dp[i][bit][0]
            dp[i+1][bit][1] += dp[i][bit][1]
        # 3,5,7への遷移
        for k, x in enumerate([3, 5, 7]):
            dp[i+1][bit|1<<k][1] += dp[i][bit][1]
            if a == x:
                dp[i+1][bit|1<<k][0] += dp[i][bit][0]
            elif a > x:
                dp[i+1][bit|1<<k][1] += dp[i][bit][0]
# N桁見終わって、3,5,7出現済(bit=111)の合計
print(dp[N][-1][0] + dp[N][-1][1])

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:
from itertools import product
N = int(input())
n = 3
ans = 0
while True:
    for s in product('357', repeat=n):
        s = ''.join(s)
        if N < int(s):
            break
        if '3' in s and '5' in s and '7' in s:
            ans += 1
    else:
        n += 1
        continue
    break
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
    for c in "753":ret+=dfs(s+c)
    return ret
print(dfs("0"))

Submission status: Accepted

Solution code:
import itertools

N = input()
count = 0
list = ["3", "5", "7"]

for i in range(3, len(N)):
    # print(3**i - (2**i) * 3)
    count += 3**i - (2**i) * 3 + 3
# print(count)
for i in itertools.product(list, repeat=len(N)):
    if int("".join(i)) <= int(N):
        if "3" in i and "5" in i and "7" in i:
            # print("".join(i))
            count += 1
print(count)

Submission status: Accepted

Solution code:
N = int(input())
N753 = set()


def dfs(depth, s):
    if depth == 9:
        n = int(s)
        if '0' not in str(n) \
            and '3' in str(n) \
            and '5' in str(n) \
            and '7' in str(n):
            N753.add(n)
        return

    dfs(depth+1, s+'0')
    dfs(depth+1, s+'3')
    dfs(depth+1, s+'5')
    dfs(depth+1, s+'7')

dfs(0, '')

ans = len([n for n in N753 if n <= N])
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque

N=int(input())
M=3**9+1
S="357"
vX=[]
appX=vX.append

vQ = deque(S)
tp = vQ.popleft
pb = vQ.append

while vQ:
  p = tp()
  if len(p)<9:
    for n in S:
      c = p + n
      pb(c)
      if all(s in c for s in S):
        appX(int(c))
print(vX[:20], file=sys.stderr)

print(sum(x<=N for x in vX))

Submission status: Accepted

Solution code:
N = int(input())
def dfs(s):
  if int(s)>N:
    return 0
  else:
    if "3" in s and "5" in s and "7" in s:
      ret=1
    else:
      ret=0
  
    for i in "357":
      ret+=dfs(s+i)
    return ret
  
print(dfs("0"))

Submission status: Accepted

Solution code:
import itertools
s = int(input())
N = len(str(s))
def A(n):
    return (3 ** n) - (3 * 2 ** n) + 3
ans = 0
if s < 357:
    print(0)
elif N > 3:
    for i in range(N-1,2,-1):
        ans += A(i)
    seq = ("3","5","7")
    S = list(itertools.product(seq,repeat=N))
    for j in S:
        j = list(j)
        if "3" in j and "5" in j and "7" in j:
            j = "".join(j)
            if int(j) <= s:
                ans += 1
    print(ans)
elif N == 3:
    seq = ("3","5","7")
    S = list(itertools.product(seq,repeat=N))
    for j in S:
        j = list(j)
        if "3" in j and "5" in j and "7" in j:
            j = "".join(j)
            if int(j) <= s:
                ans += 1
    print(ans)

Submission status: Accepted

Solution code:
def sft(n, num, add):
    int_sft = int(num+add)
    if int_sft > n:
        return True
    else:
        l.append(int_sft)
        sft(n, num+add, "3")
        sft(n, num+add, "5")
        sft(n, num+add, "7")

l=[]
n = int(input())
sft(n, "", "3")
sft(n, "", "5")
sft(n, "", "7")
le = []
for i in range(len(l)):
    c3 = str(l[i]).count("3")
    c5 = str(l[i]).count("5")
    c7 = str(l[i]).count("7")
    if c3 > 0 and c5 > 0 and c7 > 0:
        le.append(l[i])
print(len(list(set(le))))

Submission status: Accepted

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

ans = 0

for i in range(3,len(str(n))+1):
    for p in product('753',repeat=i):
        if n >= int(''.join(list(p))) and all(list(p).count(c) > 0 for c in '753'): ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools

n=int(input())
c=0
for i in range(len(str(n))+1):
      for j in list(itertools.product((3,5,7),repeat=i)):
            if (3 in j) and (5 in j) and (7 in j):
                  if n >=int((''.join(list(map(str,j))))):
                        c+=1
print(c)

Submission status: Accepted

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

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

print(dfs(''))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

a = int(input())
#桁数ごとのリストを作成
nums = [3,5,7]
digit_l = [[3,5,7]]
digit = 2
#9桁目までの全パターン列挙
while digit <= 9:
    #digit桁の数を生成
    temp = []
    ta = temp.append
    base = 10**(digit-1)
    for i in nums:
        for j in digit_l[digit-2]:
            ta(j+base*i)
    digit_l.append(temp)
    digit+=1
candidate = []
for i in digit_l:
    candidate += i
candidate_str = list(map(str,candidate))

check_753 = lambda x:1 if "3" in x and "5" in x and "7" in x else 0
candidate_check = list(map(check_753,candidate_str))

#2分探索, nibuntansaku,二分探索
from bisect import bisect_right
print(sum(candidate_check[0:bisect_right(candidate,a)]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

num = ['0', '3', '5', '7']
cand = []
for i1 in num:
	for i2 in num:
		for i3 in num:
			for i4 in num:
				for i5 in num:
					for i6 in num:
						for i7 in num:
							for i8 in num:
								for i9 in num:
									for i10 in num:
										s = i1+i2+i3+i4+i5+i6+i7+i8+i9+i10
										cand.append(int(s))

N = INT()
ans = []
for c in cand:
	if c <= N and	str(c).count('3') >= 1 and str(c).count('5') >= 1 and str(c).count('7') >= 1 and str(c).count('0') < 1:
		ans.append(c)

print(len(ans))

Submission status: Accepted

Solution code:
def dfs(s,n):
    if int(s)>n:
        return 0
    cur = 0
    if all(s.count(c) > 0 for c in '753'):
        cur = 1
    for c in "753":
        cur += dfs(s+c,n)
    return cur
def examC():
    N = I()
    ans = dfs("0",N)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Submission status: Accepted

Solution code:
from collections import deque

n = int(input())

qu = deque([7,5,3])
cnt = 0

while qu:
	t = qu.popleft()
	if t > n:
		continue
	if set(str(t)) == {'7','5','3'}:
		cnt += 1
	qu.append(t*10+7)
	qu.append(t*10+5)
	qu.append(t*10+3)

print(cnt)

Submission status: Accepted

Solution code:
from itertools import product as pr
n=int(input())
if n<357:
  print(0)
  exit()

l=[]
for i in range(3,len(str(n))+1):
  l+=list(pr('753',repeat=i))

ans=0

for x in l:
  if int(''.join(x))>n:
    continue
  if x.count('3')>0 and x.count('5')>0 and x.count('7')>0:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def fes(cul=0):
    if cul > N:
        return 0 
    counter = 0

    if "3" in str(cul) and "5" in str(cul) and "7" in str(cul):
        counter += 1
    counter += fes(cul * 10 + 3)
    counter += fes(cul * 10 + 5)
    counter += fes(cul * 10 + 7)

    return counter

print(fes())

Submission status: Accepted

Solution code:
N = int(input())

def fes(cul='0'):
    if int(cul) > N:
        return 0 
    counter = 0
    if "3" in cul and "5" in cul and "7" in cul:
        counter += 1
    counter += fes(cul + "3")
    counter += fes(cul + "5")
    counter += fes(cul + "7")

    return counter

print(fes())

Submission status: Accepted

Solution code:
n=int(input())
def dfs(x):
    if int(x)>n:
        return 0
    c=1 if all(x.count(l)>0 for l in "753") else 0
    for i in "753":
        c+=dfs(x+i)
    return c
print(dfs("0"))

Submission status: Accepted

Solution code:
n = int(input())

def search(s="0"):
    if int(s) > n: return 0
    cnt = 0
    if "3" in s and "5" in s and "7" in s:
        cnt += 1
    cnt += search(s + "3")
    cnt += search(s + "5")
    cnt += search(s + "7")
    return cnt
print(search())

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:
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:
def main():
    n=int(input())
    keta=len(str(n))
    ary=[]
    cnt=0
    ary.append(0)
    ary.append([3,5,7])
    # ary[keta数][その桁数の357数]
    if keta<=2:
        print(0)
        return
    for i in range(2,keta+1):
        temp=[]
        for j in range(0,3**(i-1)):
            temp3=ary[i-1][j]*10+3
            temp5=ary[i-1][j]*10+5
            temp7=ary[i-1][j]*10+7
            if '3' in str(temp3) and '5' in str(temp3) and '7' in str(temp3) and temp3 <= n :
                cnt+=1
            if '3' in str(temp5) and '5' in str(temp5) and '7' in str(temp5) and temp5 <= n:
                cnt+=1
            if '3' in str(temp7) and '5' in str(temp7) and '7' in str(temp7) and temp7 <= n:
                cnt+=1
            temp.append(temp3)
            temp.append(temp5)
            temp.append(temp7)
        ary.append(temp)
    print(cnt)
    # print(ary)
    # print(len(ary))
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
#0,7,5,3で選んでくる
x=[0,7,5,3]
a=[]
k=0

def new_num(c):
    global x
    d=0
    for i in range(9):
        d+=(10**i)*x[c[i]]
    return d

for i0 in range(4):
    for i1 in range(4):
        for i2 in range(4):
            for i3 in range(4):
                for i4 in range(4):
                    for i5 in range(4):
                        for i6 in range(4):
                            for i7 in range(4):
                                for i8 in range(4):
                                    l1=new_num([i0,i1,i2,i3,i4,i5,i6,i7,i8])
                                    l2=str(l1)
                                    if ("3" in l2) and ("5" in l2) and ("7" in l2) and ("0" not in l2):
                                        a.append(l1)
a.sort()
co=0
n=int(input())
for i in a:
    if i<=n:
        #print(i)
        co+=1
    else:
        break
print(co)

Submission status: Accepted

Solution code:
N = input()
n = len(N)
N = int(N)
s = ["1","7","5","3"]
ans = 0
for i in range(4**n):
    st = "0"
    while i != 0:
        st = st + s[i%4]
        i = i//4
    if "1" in st:
        b = False
    else:
        b = True
    for j in s[1:]:
        if not j in st:
            b = False
    if b and int(st) <= N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

ans=0
def make753(s,n):
  global ans
  if s<=N:
    if "3" in str(s) and "5" in str(s) and "7" in str(s):
      ans+=1
  if n>0:
    for i in 7,5,3:
      make753(10*s+i,n-1)
      
make753(0,len(str(N)))
print(ans)

Submission status: Accepted

Solution code:
N = int(input().strip())

def f(s):
    if int(s) > N:
        return 0
    
    ret = 1 if all([c in s for c in '753']) else 0
    for c in '753':
        ret += f(s + c)
    
    return ret

print(f('0'))

Submission status: Accepted

Solution code:
from itertools import product
n = input()
p = []
for i in range(len(n)):
	p += list(product(["7","5","3"], repeat = i+1))
a = []
for i in p:
	if ("7" not in i) or ("5" not in i) or ("3" not in i):
		continue
	else:
		if int("".join(i)) <= int(n):
			a.append(int("".join(i)))
print (len(a))

Submission status: Accepted

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

def dfs(s):
    global count_num
    global taegrt
    global ans 
    for val in taegrt:
        tmp = s+val
        if int(tmp) > n:
            return
        if tmp in count_num:
            continue
        count_num.append(tmp)
        #print(tmp)
        if "7" in list(tmp) and "5" in list(tmp) and "3" in list(tmp):
            ans += 1
        dfs(tmp)

for i in taegrt:
    dfs(i)

print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time

input = sys.stdin.readline

# input = sys.stdin.readline
sys.setrecursionlimit(2147483647)


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


def main():
    N = int(input())
    number = str(N)
    L = len(number)
    dp = [[[[[0 for t in range(2)]
                for f in range(2)]
                for s in range(2)]
                for smaller in range(2)]
                for j in range(L + 1)]

    n = []
    for i in range(L):
        n.append(int(number[i]))

    # k,smaller,7,5,3
    dp[0][0][0][0][0] = 1

    for k in range(L):
        for smaller in range(2):
            for s in range(2):
                for f in range(2):
                    for t in range(2):
                        li = [0, 7, 5, 3] if smaller else [q for q in [0, 7, 5, 3] if q <= n[k]]
                        for m in li:
                            if k + 2 == L:
                                if s == 1 and f == 0 and t == 0 and m != 7:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 0 and f == 1 and t == 0 and m != 5:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 0 and f == 0 and t == 1 and m != 3:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                # print('k+2', k)
                            elif k + 1 == L:
                                if s == 0 and f == 1 and t == 1 and m == 7:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 1 and f == 0 and t == 1 and m == 5:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 1 and f == 1 and t == 0 and m == 3:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                # print('k+1', k)
                            else:
                                if s == 0 and f == 0 and t == 0 and m == 0:
                                    dp[k+1][1][0][0][0] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
        # print(k+1)
        # print('dp[k+1][0][0][0][0]', dp[k+1][0][0][0][0])
        # print('dp[k+1][0][0][0][1]', dp[k+1][0][0][0][1])
        # print('dp[k+1][0][0][1][0]', dp[k+1][0][0][1][0])
        # print('dp[k+1][0][0][1]11]', dp[k+1][0][0][1][1])
        # print('dp[k+1][0][1][0][0]', dp[k+1][0][1][0][0])
        # print('dp[k+1][0][1][0][1]', dp[k+1][0][1][0][1])
        # print('dp[k+1][0][1][1][0]', dp[k+1][0][1][1][0])
        # print('dp[k+1][0][1][1][1]', dp[k+1][0][1][1][1])
        # print('dp[k+1][1][0][0][0]', dp[k+1][1][0][0][0])
        # print('dp[k+1][1][0][0][1]', dp[k+1][1][0][0][1])
        # print('dp[k+1][1][0][1][0]', dp[k+1][1][0][1][0])
        # print('dp[k+1][1][0][1][1]', dp[k+1][1][0][1][1])
        # print('dp[k+1][1][1][0][0]', dp[k+1][1][1][0][0])
        # print('dp[k+1][1][1][0][1]', dp[k+1][1][1][0][1])
        # print('dp[k+1][1][1][1][0]', dp[k+1][1][1][1][0])
        # print('dp[k+1][1][1][1][1]', dp[k+1][1][1][1][1])
        # print('=========================')

    # print(dp[L][0][1][1][1])
    # print(dp[L][1][1][1][1])
    print(dp[L][0][1][1][1] + dp[L][1][1][1][1])


def sub():
    N = int(input())
    number = str(N)
    length = len(number)
    ans = 0

    stack = ['']
    while len(stack) > 0:
        s = stack.pop()

        if len(s) >= length:
            remain = set([s[i] for i in range(len(s))]) - set('0')
            if len(remain) == 3 and int(s) <= N:
                ans += 1
                # print(s)
            continue

        for i in ['0', '7', '5', '3']:
            if (i == '0' and len(s) == 0) or (len(s) > 0 and s[-1] == '0'):
                stack.append(s + i)
            elif i != '0':
                stack.append(s + i)

    print(ans)


if __name__ == '__main__':
    sub()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time

input = sys.stdin.readline

# input = sys.stdin.readline
sys.setrecursionlimit(2147483647)


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


def main():
    N = int(input())
    number = str(N)
    L = len(number)
    dp = [[[[[0 for t in range(2)]
                for f in range(2)]
                for s in range(2)]
                for smaller in range(2)]
                for j in range(L + 1)]

    n = []
    for i in range(L):
        n.append(int(number[i]))

    # k,smaller,7,5,3
    dp[0][0][0][0][0] = 1

    for k in range(L):
        for smaller in range(2):
            for s in range(2):
                for f in range(2):
                    for t in range(2):
                        li = [0, 7, 5, 3] if smaller else [q for q in [0, 7, 5, 3] if q <= n[k]]
                        for m in li:
                            if k + 2 == L:
                                if s == 1 and f == 0 and t == 0 and m != 7:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 0 and f == 1 and t == 0 and m != 5:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 0 and f == 0 and t == 1 and m != 3:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                # print('k+2', k)
                            elif k + 1 == L:
                                if s == 0 and f == 1 and t == 1 and m == 7:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 1 and f == 0 and t == 1 and m == 5:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif s == 1 and f == 1 and t == 0 and m == 3:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
                                # print('k+1', k)
                            else:
                                if s == 0 and f == 0 and t == 0 and m == 0:
                                    dp[k+1][1][0][0][0] += dp[k][smaller][s][f][t]
                                elif m != 0:
                                    dp[k+1][smaller or m < n[k]][s == 1 or m == 7][f == 1 or m == 5][t == 1 or m == 3] += dp[k][smaller][s][f][t]
        # print(k+1)
        # print('dp[k+1][0][0][0][0]', dp[k+1][0][0][0][0])
        # print('dp[k+1][0][0][0][1]', dp[k+1][0][0][0][1])
        # print('dp[k+1][0][0][1][0]', dp[k+1][0][0][1][0])
        # print('dp[k+1][0][0][1]11]', dp[k+1][0][0][1][1])
        # print('dp[k+1][0][1][0][0]', dp[k+1][0][1][0][0])
        # print('dp[k+1][0][1][0][1]', dp[k+1][0][1][0][1])
        # print('dp[k+1][0][1][1][0]', dp[k+1][0][1][1][0])
        # print('dp[k+1][0][1][1][1]', dp[k+1][0][1][1][1])
        # print('dp[k+1][1][0][0][0]', dp[k+1][1][0][0][0])
        # print('dp[k+1][1][0][0][1]', dp[k+1][1][0][0][1])
        # print('dp[k+1][1][0][1][0]', dp[k+1][1][0][1][0])
        # print('dp[k+1][1][0][1][1]', dp[k+1][1][0][1][1])
        # print('dp[k+1][1][1][0][0]', dp[k+1][1][1][0][0])
        # print('dp[k+1][1][1][0][1]', dp[k+1][1][1][0][1])
        # print('dp[k+1][1][1][1][0]', dp[k+1][1][1][1][0])
        # print('dp[k+1][1][1][1][1]', dp[k+1][1][1][1][1])
        # print('=========================')

    # print(dp[L][0][1][1][1])
    # print(dp[L][1][1][1][1])
    print(dp[L][0][1][1][1] + dp[L][1][1][1][1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools as it

N = input()
list_753 = []
for i in range(3, len(N) + 1):
    for i_753 in it.product("357", repeat=i):
        if "3" in i_753 and "5" in i_753 and "7" in i_753:
            list_753.append(int("".join(i_753)))

ans = 0
for i in list_753:
    if i <= int(N):
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
def sitigo(num):
    if int(num) > n:
        return 0
    count3 = False
    count5 = False
    count7 = False
    s = 0

    for i in range(len(str(num))):
        if str(num)[i] == "3":
            count3 = True
        if str(num)[i] == "5":
            count5 = True
        if str(num)[i] == "7":
            count7 = True
        if count3 and count5 and count7:
            s = 1

    return sitigo(int(str(num)+"3")) + sitigo(int(str(num)+"5")) + sitigo(int(str(num)+"7")) + s
print(sitigo(0))

Submission status: Accepted

Solution code:
n=int(input())

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

print(dfs("0"))

Submission status: Accepted

Solution code:
from itertools import product

N=int(input())

k=len(str(N))

l=[3,5,7]

P_list=[]

for j in range(3,k+1):
    for i in product(l,repeat=j):
        temp=list(map(str,i))
        P_list.append("".join(temp))

cnt=0

for i in P_list:
    if ("3" in i) and ("5" in i) and ("7" in i):
        if int(i)<=N:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
keta=len(str(n))
for i in range(3,keta):
    ans+=3**i-2**i*3+3
    # print(ans)
ite=list(itertools.product((3,5,7),repeat=keta))
ite.sort()
for ii in ite:
    bi=list(map(str,ii))
    ai = int(''.join(bi))
    if n>=ai:
        if (3 in ii) and (5 in ii) and  (7 in ii):
            ans+=1
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

numlist = []
keta = len(str(N-1))
for k in range(3,keta+1):
    for i in range(3**k):
        cur = ''
        tmp = i
        tk = 0
        while tk<k:
            cur += str(tmp%3)
            tmp //= 3
            tk += 1

        numlist.append(cur)

ans = 0
coeff = [3,5,7]
for s in numlist:
    if len(s)<3 :continue
    flag = [False,False,False]
    val = 0
    base = 1
    for t in s:
        flag[int(t)] = True
        val += coeff[int(t)] * base
        base *= 10
    if (sum(flag)==3) and (val <= N):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
d = len(str(N))
ans = []
for i in range(3, d+1):
    cs = product([3,5,7], repeat=i)
    for c in cs:
        if set(c) == {3, 5, 7}:
            if i < d or (i == d and int(''.join(map(str, c))) <= N):
                ans.append(c)
print(len(ans))

Submission status: Accepted

Solution code:
import itertools

N = int(input())
M=len(str(N))
count=0
for i in range(3,M):
  for x in itertools.product('357',repeat=i):
    if '3' in x and '5' in x and '7' in x:
      count +=1
for x in itertools.product('357',repeat=M):
  if '3' in x and '5' in x and '7' in x:
    x_i =0
    for j in range(len(x)):
      x_i +=int(x[j])*10**(len(x)-j-1)
    if x_i<=N:
      count +=1
print(count)

Submission status: Accepted

Solution code:
n = int(input())

sitigosan_list = [3, 5, 7]
count = 0

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

def make_753(num):
    global count
    b = str(num) + '3'
    c = str(num) + '5'
    d = str(num) + '7'
    if int(b) > n:
        return
    elif '3' in str(b) and '5' in str(b) and '7' in str(b):
        count += 1
        make_753(b)
    else:
        make_753(b)
    if int(c) > n:
        return
    elif '3' in str(c) and '5' in str(c) and '7' in str(c):
        count += 1
        make_753(c)
    else:
        make_753(c)
    if int(d) > n:
        return
    elif '3' in str(d) and '5' in str(d) and '7' in str(d):
        count += 1
        make_753(d)
    else:
        make_753(d)


make_753('')

print(count)

Submission status: Accepted

Solution code:
N = input()


def dfs(s=""):
    if s != "":
        if int(s) > int(N):
            return 0
    if (len(s) == s.count("7") + s.count("5") + s.count("3")) and (s.count("7") >= 1 and s.count("5") >= 1 and s.count("3") >= 1):
        ret = 1
    else:
        ret = 0
    for l in ["3", "5", "7"]:
        ret += dfs(s+l)

    return ret


print(dfs(""))

Submission status: Accepted

Solution code:
n=int(input())
length = len(str(n))+1
se = set()
def moji(s):
    if len(s)>=length:
        return
    se.add(s)
    moji(s+'5')
    moji(s+'7')
    moji(s+'3')
moji('')
li=list(sorted(se))
ans = 0
for i in li:
    if i == '':
        continue
    if '3' not in i or '5' not in i or '7' not in i:
        continue
    if int(i)<=n:
        ans+=1
print(ans)