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:
t=["0","3","5","7"]
s=["3","5","7"]
n=int(input())
ans=chk=0
for a in t:
    for b in t:
        for c in t:
            for d in t:
                for e in t:
                    for f in t:
                        for g in s:
                            for h in s:
                                for i in s:
                                    x=str(int(a+b+c+d+e+f+g+h+i))
                                    y=set(list(x))
                                    if ("0" not in y) and (len(y)==3) and (int(x)<=n):
                                        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def nngg(m):
    if int(m) > n:
        return 0
    ret = 1 if all(m.count(s)>0 for s in '375') else 0
    for s in '357':
        ret += nngg(m+s)
    return ret

print(nngg('0'))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
    if int(s)>N: 
        return 0
    for c in list("753"):
        if s.count(c) < 1:
            ret = 0
            break
    else:
        ret = 1
    for c in list("753"):
        ret += dfs(s+c)
    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
from itertools import product, count

n = int(input())
cnt = 0
flag = False
for i in count(1):
    for digits in product((3,5,7), repeat=i):
        if len(set(digits)) < 3:
            continue
        x = sum(10**j * d for j,d in enumerate(reversed(digits)))
        if x > n:
            flag = True
            break
        else:
            cnt += 1
    if flag:
        break

print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
def f(s):
    t=s
    num=0
    ten=1
    L=[0,0,0,1]
    while t!=0:
        a=t%4
        if a==1:
            num+=3*ten
            L[0]=1
        elif a==2:
            num+=5*ten
            L[1]=1
        elif a==3:
            num+=7*ten
            L[2]=1
        elif a==0:
            L[3]=0
        ten*=10
        t=t//4
    return num,L
ans=0
for i in range(1,4**9):
    num,L=f(i)
    if num<=N and L==[1,1,1,1]:
        ans+=1
        #print(num)
print(ans)

Submission status: Accepted

Solution code:
import itertools
max_753_numbers = {2: 0}
for i in range(3, 10):
    max_753 = pow(3, i) - (3 * pow(2, i) - 3 * pow(1, i))
    max_753_numbers[i] = max_753_numbers[i-1] + max_753


def main():
    n_str = input()
    if len(n_str) <= 2:
        print(0)
        return
    n = int(n_str)

    base_number = max_753_numbers[len(n_str)-1]
    cnt= 0
    for combi in itertools.product('357', repeat=len(n_str)):
        if '3' in combi and '5' in combi and '7' in combi:
            if int(''.join(combi)) <= n:
                cnt += 1

    ans = base_number + cnt
    print(ans)
    return



main()

Submission status: Accepted

Solution code:
# coding:utf-8

import itertools

N = int(input())

ans = 0
for i in range(2, len(str(N))):
    for s in itertools.product('753', repeat=i+1):
        if int(''.join(s)) > N:
            continue
        if all(s.count(c) > 0 for c in '753'):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# 解説放送
def dfs(x):
    if x > N: return 0
    res = 1 if all(c in str(x) for c in '753') else 0
    for v in 3, 5, 7:
        res += dfs(10 * x + v)
    return res


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

Submission status: Accepted

Solution code:
from bisect import bisect
x,z = [[357,375,537,573,735,753]],[]
for _ in range(4,10):
	y = set()
	for i in list(x[-1]):
		for j in ["3","5","7"]:
			for k in range(_): y.add(int(str(i)[:k]+j+str(i)[k:]))
	x.append(y)
for i in x:
	for j in i: z.append(j)
z.sort()
n = int(input())
print(bisect(z,n))

Submission status: Accepted

Solution code:
N = int(input())

# ここで、七五三数とは以下の条件を満たす正の整数です。
# 十進法で表記したとき、数字 7, 5, 3 がそれぞれ 1 回以上現れ、これら以外の数字は現れない。


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 check(var):
    in_range = var <= N
    all_num_in = all(c in str(var) for c in '753')
    return in_range and all_num_in


def dfs(x):
    res = 0
    if check(x):
        res += 1
    if x <= N:
        res += dfs(10 * x + 3)
        res += dfs(10 * x + 5)
        res += dfs(10 * x + 7)
    return res


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

Submission status: Accepted

Solution code:
n = int(input())

count = 0
def dfs(now, conb):
    global count
    if '3' in conb and '5' in conb and '7' in conb and n >= int(conb):
        count += 1
    if now < 10:
        for i in ['3', '5', '7']:
            dfs(now + 1, conb + i)

dfs(0, '0')
print(count)

Submission status: Accepted

Solution code:
n = int(input())
d = len(str(n)) - 1
k = str(n)
j = int(k[0])
count = 1
co = 0
for i9 in range(3, 8, 2):
    for i8 in range(3, 8, 2):
        for i7 in range(3, 8, 2):
            for i6 in range(3, 8, 2):
                for i5 in range(3, 8, 2):
                    for i4 in range(3, 8, 2):
                        for i3 in range(3, 8, 2):
                            for i2 in range(3, 8, 2):
                                for i1 in range(3, 8, 2):
                                    if len(set([i9,i8,i7,i6,i5,i4,i3,i2,i1])) == 3:
                                        t = int(str(i9) + str(i8) + str(i7) + str(i6) + str(i5) + str(i4) + str(i3) + str(i2) + str(i1))
                                        if t <= n:
                                            co += 1
for i8 in range(3, 8, 2):
    for i7 in range(3, 8, 2):
        for i6 in range(3, 8, 2):
            for i5 in range(3, 8, 2):
                for i4 in range(3, 8, 2):
                    for i3 in range(3, 8, 2):
                        for i2 in range(3, 8, 2):
                            for i1 in range(3, 8, 2):
                                if len(set([i8,i7, i6, i5, i4, i3, i2, i1])) == 3:
                                    t = int(str(i8) + str(i7) + str(i6) + str(i5) + str(i4) + str(i3) + str(i2) + str(i1))
                                    if t <= n:
                                        co += 1
for i7 in range(3, 8, 2):
    for i6 in range(3, 8, 2):
        for i5 in range(3, 8, 2):
            for i4 in range(3, 8, 2):
                for i3 in range(3, 8, 2):
                    for i2 in range(3, 8, 2):
                        for i1 in range(3, 8, 2):
                            if len(set([i7, i6, i5, i4, i3, i2, i1])) == 3:
                                t = int(str(i7) + str(i6) + str(i5) + str(i4) + str(i3) + str(i2) + str(i1))
                                if t <= n:
                                    co += 1

for i6 in range(3, 8, 2):
    for i5 in range(3, 8, 2):
        for i4 in range(3, 8, 2):
            for i3 in range(3, 8, 2):
                for i2 in range(3, 8, 2):
                    for i1 in range(3, 8, 2):
                        if len(set([i6, i5, i4, i3, i2, i1])) == 3:
                            t = int(str(i6) + str(i5) + str(i4) + str(i3) + str(i2) + str(i1))
                            if t <= n:
                                co += 1
for i5 in range(3, 8, 2):
    for i4 in range(3, 8, 2):
        for i3 in range(3, 8, 2):
            for i2 in range(3, 8, 2):
                for i1 in range(3, 8, 2):
                    if len(set([i5, i4, i3, i2, i1])) == 3:
                        t = int(str(i5) + str(i4) + str(i3) + str(i2) + str(i1))
                        if t <= n:
                            co += 1
for i4 in range(3, 8, 2):
    for i3 in range(3, 8, 2):
        for i2 in range(3, 8, 2):
            for i1 in range(3, 8, 2):
                if len(set([i4, i3, i2, i1])) == 3:
                    t = int(str(i4) + str(i3) + str(i2) + str(i1))
                    if t <= n:
                        co += 1
for i3 in range(3, 8, 2):
    for i2 in range(3, 8, 2):
        for i1 in range(3, 8, 2):
            if len(set([i3, i2, i1])) == 3:
                t = int(str(i3) + str(i2) + str(i1))
                if t <= n:
                    co += 1

print(co)
"""for i in range(3, d):
    co += 3 ** i - 3 * 2 ** i + 3
if 0 < j < 3:
    co += 3 ** d - 3 * 2 ** d + 3
elif 3 <= j < 5:
    for u
elif 5 <= j < 7:
    count *= 2
elif 7 <= j:
    count *= 3"""
"""li = [6, ]
for i in range(d, 0, -1):
    if i >= 3:
        count *= 3
    elif i == 2 and d + 1 > 2:
        count *= 2
    elif d + 1 <= 2:
        count = 0
if 5 <= j < 7:
    count *= 2
elif 7 <= j:
    count *= 3
print(count)"""

Submission status: Accepted

Solution code:
n=int(input())
p=len(list(str(n)))
s=[3,5,7]
l=0
for i in range(2,p+1):
    for j in range(l,l+3**i):
        s+=[s[j]*10+3,s[j]*10+5,s[j]*10+7]
    else:
        l+=3**i
s=s[12:]
c=0
for i in range(len(s)):
    if s[i]<=n:
        if len(set(list(str(s[i]))))==3:
            c+=1
print(c)

Submission status: Accepted

Solution code:
N = int(input())


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


print(dfs('0'))

Submission status: Accepted

Solution code:
from copy import deepcopy
n = input()
ans = 0
li = ["3", "5", "7"]
st = ["3", "5", "7"]
are = []
for i in range(len(n)-1):
    for i in range(len(st)):
        for j in range(len(li)):
            k = st[i] + li[j]
            are.append(k)
            if k.count("3") >= 1 and k.count("5") >= 1 and k.count("7") >= 1 and int(k) <= int(n):
                ans += 1
    li = deepcopy(are)
    are = []
print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


N = int(input())


def DFS(s):
    if int(s) > N:
        return 0

    if all(s.count(c) > 0 for c in '753'):
        ret = 1
    else:
        ret = 0

    for c in '753':
        ret += DFS(s + c)
    return ret


print(DFS('0'))

Submission status: Accepted

Solution code:
from itertools import product
from collections import Counter

if __name__ == '__main__':
    n = input()
    length = len(n)
    ans = 0
    for i in range(length + 1):
        for s in (''.join(list(t)) for t in product(*(['357'] * i))):
            s = (' ' * (length - i)) + s
            if n < s:
                break
            count_set = set(Counter(s.strip()).keys())
            if count_set != {'3', '5', '7'}:
                continue
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
from itertools import chain
n = input()
target = list([[""]])

def next753(string_list):
    x = []
    for string in string_list:
        x.append("3" + string)
        x.append("5" + string)
        x.append("7" + string)
    return x

ans = 0
for i in range(0, len(n)):
    target.append(next753(target[i]))
new = filter(lambda x: int(x) <= int(n),list(chain.from_iterable(target[3:])))
for i in list(new):
    if (("3" in i) and ("5" in i) and ("7" in i)):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

from itertools import product

def f(n):
    ret = 0
    i = 0
    while True:
        i += 1
        for v in product('357', repeat=i):
            v = ''.join(v)
            if int(v) > n:
                return ret
            if len(set(v)) == 3:
                ret += 1

print(f(N))

Submission status: Accepted

Solution code:
import bisect
N = int(input())
S = set([7,5,3])
for i in range(8):
    for j in S.copy():
        for k in [7,5,3]:
            S.add(10*j+k)
T = []
for i in S:
    if str(i).count('3') and str(i).count('5') and str(i).count('7'):
        T.append(i)
T.sort()
print(bisect.bisect_right(T,N))

Submission status: Accepted

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

def sss(index, is3, is5, is7, TOP, zz=False):
    counter = 0
    if index == len(N):
        if is3 and is5 and is7:
            return 1
        return 0
    if zz:
        counter += sss(index+1, False, False, False, False, True)
    if TOP:
        if int(N[index]) >= 3:
            counter += sss(index+1, True, is5, is7, int(N[index]) == 3)
        if int(N[index]) >= 5:
            counter += sss(index+1, is3, True, is7, int(N[index]) == 5)
        if int(N[index]) >= 7:
            counter += sss(index+1, is3, is5, True, int(N[index]) == 7)
    else:
        counter += sss(index+1, True, is5, is7, False)
        counter += sss(index+1, is3, True, is7, False)
        counter += sss(index+1, is3, is5, True, False)
    return counter

print(sss(0, False, False, False, True, True))

Submission status: Accepted

Solution code:
n = int(input())

count = 0

def dfs(s):
    # print(s)
    # 753数ですか？
    if int(s) > n:
        return
    if all(c in s for c in "753"):
        global count
        count += 1
    for c in "753":
        dfs(s+c)


dfs('0')

print(count)

Submission status: Accepted

Solution code:
N = int(input())


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

print(dfs("0"))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import queue

_in = input()
Nlen = len(_in)
N = int(_in)
glen = 1
ans = 0

findq = queue.Queue()
checkq = queue.Queue()

findq.put('3')
findq.put('5')
findq.put('7')

while glen <= Nlen and not findq.empty():
  head = findq.get()
  checkq.put(head)
  if len(head)+1 <= Nlen:
    glen = min(glen, len(head))
    findq.put(head+'3')
    findq.put(head+'5')
    findq.put(head+'7')

while not checkq.empty():
  head = checkq.get()
  if int(head) > N:
    continue
  checker = 0b000
  for ch in head:
    if ch == '3':
      checker |= 0b100
    elif ch == '5':
      checker |= 0b010
    elif ch == '7':
      checker |= 0b001
    else:
      checker = 0b000
      break
  if checker == 0b111:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
digit = len(str(n))+1
th_adic = [0]*digit
mask = [0,3,5,7]

def number():
  ret=0
  d=1
  for i in range(digit):
    ret+=d*mask[th_adic[i]]
    d*=10
  return ret

def appear357():
  return (1 in th_adic) and (2 in th_adic) and (3 in th_adic)

def inc():
  for i in range(digit):
    if th_adic[i] == 3:
      th_adic[i]=1
      continue
    th_adic[i]+=1
    break

ret=0
while number()<=n:
  if appear357():
    ret+=1
  inc()
print(ret)

Submission status: Accepted

Solution code:
import itertools

N = input()
seq = ('3', '5', '7')
cnt = 0

for i in range(1, len(N)+1):
    for j in itertools.product(seq, repeat=i):
        if int(''.join(j)) > int(N):
            break
        if '3' not in j or '5' not in j or '7' not in j:
            continue
        if int(''.join(j)) < 357:
            continue
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N=int(input())

L=[3,5,7]
f = 0
cnt = 0
while f == 0:
  for i in range(3):
    x = L[cnt] * 10 + L[i]
    if x > N:
      f = 1
      break
    else:
      L.append(L[cnt] * 10 + L[i])
  cnt += 1

ans = set(["3","5","7"])
cnt = 0
for i in L:
    s = set(str(i))
    if s == ans:
        cnt += 1
print(cnt)

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 num_357(ls, i, num_l):
    l = ["3", "5", "7"]
    if i > 0:
        for c in l:
            i -= 1
            ls.append(c)
            num_l.append("".join(ls))
            num_357(ls, i, num_l)
            ls.pop(-1)
            i += 1
    else:
        return

num_l = []
ls = []
i =9 

num_357(ls, i, num_l)
num_new = []
for l in num_l:
    if "3" in l and "5" in l and "7" in l:
        num_new.append(int(l))
N = int(input())
if N in num_new:
    num_new.sort()
    print(num_new.index(N)+1)
else:
    num_new.append(N)
    num_new.sort()
    print(num_new.index(N))

Submission status: Accepted

Solution code:
def is753(n):
    if n % 10 != 3 and n % 10 != 5 and n % 10 !=7:
        return False
    exist3 = False
    exist5 = False
    exist7 = False
    a = str(n)
    for i in range (len(a)):
        x = n % 10
        if x == 3 :
            exist3 = True
        elif x == 5 :
            exist5 = True
        elif x == 7 :
            exist7 = True
        else :
            return False
        n = n // 10
    if exist3 and exist5 and exist7:
        return True
    else :
        return False

n = int(input())
a = len(str(n))
lst = [[3,5,7]]
tfs = [3,5,7]
for i in range(1,a):
    l = []
    for v in lst[i-1]:
        for t in tfs:
            l.append(int(str(v) + str(t)))
    lst.append(l)
s = 0
for l in lst:
    for v in l:
        if is753(v) and v <= n:
            s+=1
print(s)

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())
ans = 0
for k in range(3,len(str(N))+1):
    for ptn in product((3,5,7), repeat=k):
        if 3 in ptn and 5 in ptn and 7 in ptn:
            if int(''.join([str(i) for i in ptn])) <= N:
                ans += 1
            else:
                break
print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
S = set([7,5,3])
for i in range(8):
    for j in S.copy():
        for k in [7,5,3]:
            S.add(int(str(j)+str(k)))
S = list(sorted(S))
T = []
for i in S:
    if str(i).count('3') and str(i).count('5') and str(i).count('7'):
        T.append(i)
print(bisect.bisect_right(T,N))

Submission status: Accepted

Solution code:
import itertools

def judge(lis):
    l = list(str(int("".join(lis))))
    if "3" in l:
        if "5" in l:
            if "7" in l:
                if not "0" in l:
                    return True
    else:
        return False

N = int(input())
length = len(str(N))

count = 0
seq = ("0", "3", "5", "7")
jun = list(itertools.product(seq, repeat=length))

for i in jun:
    num = int("".join(list(i)))
    if N >= num:
        if judge(list(i)):
            count += 1
        
print(count)

Submission status: Accepted

Solution code:
# https://img.atcoder.jp/abc114/editorial.pdf
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('') と書きたいが 6 行目でのエラーを防ぐため仕方なく

Submission status: Accepted

Solution code:
S = {3, 5, 7}
for _ in range(8):
    for x in list(S):
        for d in [3, 5, 7]:
            S |= {x * 10 + d}
N = int(input())
print(sum(e <= N and len(set(str(e))) == 3 for e in S))

Submission status: Accepted

Solution code:
N = int(raw_input())

l = ['0']
count = 0

while l:
    s = l.pop()
    if N < int(s):
        continue
    if s[0] == '0':
        s = s[1:]
    count_3 = 0
    count_5 = 0
    count_7 = 0
    for i in s:
        if i == '3':
            count_3 += 1
        elif i == '5':
            count_5 += 1
        elif i == '7':
            count_7 += 1
    if len(s) == (count_3 + count_5 + count_7) and count_3 and count_5 and count_7:
        count += 1
    for j in '357':
        l.append(s+j)

print count

Submission status: Accepted

Solution code:
n=input()
ans=0
a=len(n)
c_lst=[6, 42, 192, 732, 2538, 8334, 26484]
if int(n)>777777777:
    print(c_lst[-1])
    exit()
elif a<=2:
    print(0)
    exit()
elif a>=4:
    ans=c_lst[a-4]

from itertools import product
l_lst=["3","5","7"]
for i in product(l_lst,repeat=a):
    s="".join(i)
    if "3" in s and "5" in s and "7" in s:
        if int(s)<=int(n):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
sts={""}
for _ in range(len(str(N))):sts=sts|{s+t for t in"357"for s in sts}
print(len([int(s)for s in sts if'3'in s and'5'in s and'7'in s and int(s)<=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 collections import deque
import bisect
N=int(input())
D=deque()
L=["3","5","7"]
#ans3
i1=0
i2=0
i3=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            s=L[i1]+L[i2]+L[i3]
            if "3" in s and "5" in s and "7" in s:
                D.append(int(s))
i1=0
i2=0
i3=0
i4=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                s=L[i1]+L[i2]+L[i3]+L[i4]
                if "3" in s and "5" in s and "7" in s:
                    D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]
                    if "3" in s and "5" in s and "7" in s:
                        D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]
                        if "3" in s and "5" in s and "7" in s:
                            D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
i7=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        for i7 in range(3):
                            s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]+L[i7]
                            if "3" in s and "5" in s and "7" in s:
                                D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
i7=0
i8=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        for i7 in range(3):
                            for i8 in range(3):
                                s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]+L[i7]+L[i8]
                                if "3" in s and "5" in s and "7" in s:
                                    D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
i7=0
i8=0
i9=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        for i7 in range(3):
                            for i8 in range(3):
                                for i9 in range(3):
                                    s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]+L[i7]+L[i8]+L[i9]
                                    if "3" in s and "5" in s and "7" in s:
                                        D.append(int(s))
d=list(D)
d.sort()
print(bisect.bisect_right(d,N))

Submission status: Accepted

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

print(dfs('0'))

Submission status: Accepted

Solution code:
import sys

ans = 0


def dfs(rest: int, s: str) -> None:
    global ans
    if rest == 0:
        if int(s) > n:
            print(ans)
            sys.exit()
        elif '3' in s and '5' in s and '7' in s:
            ans += 1
    else:
        for c in "357":
            dfs(rest - 1, s + c)


def main() -> None:
    global n
    n = int(input())
    for i in range(1, sys.maxsize):
        dfs(i, "")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
ans = 0
for k in range(3,11):
    for i in product([0,3,5,7],repeat=k):
        if set(i) != {3,5,7}:
            continue
        if sum([10**j*v for j,v  in enumerate(i)]) <= N:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def ten_to_3(X):
    num = ''
    while X != 0:
        num = str(X % 3) + num
        X //= 3

    return num

N = int(input())
counter = 0

for k in range(len(str(N)), 2, -1):
    for i in range(3 ** k):
        case = ten_to_3(i)
        case = '0' * (k - len(case)) + case
        if '0' not in case or '1' not in case or '2' not in case:
            continue
        num = ''
        for j in range(len(case)):
            if case[j] == '0':
                num += '3'

            elif case[j] == '1':
                num += '5'

            else:
                num += '7'

        if int(num) <= N:
            counter += 1

print(counter)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a = [3,5,7]
b = list(itertools.product(a,a,a)) + list(itertools.product(a,a,a,a)) + list(itertools.product(a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a,a,a))
ans = 0
for i in range(len(b)):
    sb = set(b[i])
    if len(sb) == 3 and 3 in sb and 5 in sb and 7 in sb:
        c = ''.join(map(str,b[i]))
        c = int(c)
        if c <= n:
            ans +=1
        else:
            break
print(ans)