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:
n = int(input())

def dfs(x):
    if int(x)>n:
        return 0
    ans = [0,1][all(x.count(i) for i in "753")]
    for i in "753":
        ans += dfs(x+i)
    return ans
print(dfs("0"))

Submission status: Accepted

Solution code:
n = int(input())
from collections import deque
d = deque([0])
cnt = 0
while d[-1] <= n:
    x = d.popleft()
    for i in range(3,8,2):
        d.append(x * 10 + i)
        cnt += 1 if all(str(x * 10 + i).count(c)>0 for c in "753") else 0
ans=0
if d[-3] > n:
    for i in range(1,4):
        ans += 1 if all(str(d[-i]).count(c) > 0 for c in "753") else 0
    print(cnt - ans)
elif d[-2] > n:
    for i in range(1,2):
        ans += 1 if all(str(d[-i]).count(c) > 0 for c in "753") else 0
    print(cnt - ans)
elif d[-1] > n:
    if all (str(d[-1]).count(c) > 0 for c in "753"):
        print(cnt - 1)
    else:
        print(cnt)

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
product_list = []
for i in range(3, len(str(n))+1):
    product_list += list(product("753", repeat=i))  # iの長さの重複順列
#print(product_list)
count = 0
for item in product_list:
    if "3" not in item:
        continue
    if "5" not in item:
        continue
    if "7" not in item:
        continue
    item_int = int("".join(item))
    if item_int <= n:
        count += 1
print(count)

Submission status: Accepted

Solution code:
import sys 
sys.setrecursionlimit(1000000)

def dfs(A, i):
    if i > N:
        return A
    if len(str(i)) >= 3:
        if "3" in str(i) and "5" in str(i) and "7" in str(i):
            A.append(i) # 入力をイメージしながらappendの位置を決める
    for v in range(3, 8 , 2):
        i = i * 10 + v
        dfs(A, i)
        i = int(str(i)[:len(str(i))-1])

N = int(input())
B = []
for i in range(3, 8, 2):
    A = []
    dfs(A, i)
    B = B + A
print(len(B))

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
cnt = 0
num_lst = [3, 5, 7]
stack = deque([3, 5, 7])
while len(stack) > 0:
    now_num = stack.popleft()
    if now_num > n:
        break
    if len(set(str(now_num))) == 3:
        cnt += 1
    for x in num_lst:
        next_num = str(now_num) + str(x)
        next_num = int(next_num)
        stack.append(next_num)

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
def dfs(v):
    global ans
    if v > N: return 0
    if len(set(str(v))) == 3: ans += 1
    for i in (3,5,7):
        dfs(v*10+i)
dfs(0)
print(ans)

Submission status: Accepted

Solution code:
N = input()
D = len(N)
N = int(N)
ans = 0
def dfs(v):
    global ans
    if v > N: return 0
    if len(set(str(v))) == 3: ans += 1
    for i in (3,5,7):
        dfs(v*10+i)

dfs(0)
print(ans)

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

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

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

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

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


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

    N = iss()
    S = []
    for i in range(1, 10):
        S += set(itertools.product('753', repeat=i))
    ret = 0
    for s in S:
        if '7' in s and '5' in s and '3' in s and int(N) >= int("".join(s)):
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()

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'))

Submission status: Accepted

Solution code:
import sys
from collections import deque

input = sys.stdin.readline


def dfs(N):
    stack = deque(["3", "5", "7"])
    num = 0
    while stack:
        n = stack.pop()
        if int(n) > N:
            continue
        num += 1 if all(s in n for s in "357") else 0
        stack.append("3" + n)
        stack.append("5" + n)
        stack.append("7" + n)
    return num


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

    ans = dfs(N)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

def func(cur, use, counter):
  if cur > N: return
  if use == 0b111: counter.append(1)  # 答えを増やす
    
  # 7を付け加える
  func(cur * 10 + 7, use | 0b001, counter)
  # 5を付け加える
  func(cur * 10 + 5, use | 0b010, counter)
  # 3を付け加える
  func(cur * 10 + 3, use | 0b100, counter)
  
res = []
func(0, 0, res)
print(sum(res))

Submission status: Accepted

Solution code:
import numpy as np


def enum_753_number():
    enum_array = [3, 5, 7]
    enum_array = enum_753_number_(enum_array, 1)
    return enum_array


def enum_753_number_(enum_array, now_digit):
    now_digit += 1;
    if (now_digit > 9):
        return enum_array
    else:
        enum_3_array = [10*num + 3 for num in enum_array]
        enum_5_array = [10*num + 5 for num in enum_array]
        enum_7_array = [10*num + 7 for num in enum_array]
        enum_array.extend(enum_753_number_(enum_3_array, now_digit))
        enum_array.extend(enum_753_number_(enum_5_array, now_digit))
        enum_array.extend(enum_753_number_(enum_7_array, now_digit))
        return enum_array


def check_753_number(number):
    flag_3 = False
    flag_5 = False
    flag_7 = False
    if (number < 100):
        return False
    while (number > 1):
        if (number % 10 == 3): flag_3 = True
        if (number % 10 == 5): flag_5 = True
        if (number % 10 == 7): flag_7 = True
        number = int(number / 10)
    if (flag_3 == True and flag_5 == True and flag_7 == True):
        return True
    else:
        return False


def main():
    string = input()
    N = int(string)
    count = 0
    enum_array = enum_753_number()
    for elem in enum_array:
        if (elem <= N and check_753_number(elem)): count+=1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())

def dfs(cur,use,counter):
    if cur>N:
        return 0
    
    counter=int(use==0b111)

    counter+=dfs(cur*10+7,use | 0b001, counter)
    counter+=dfs(cur*10+5,use | 0b010, counter)
    counter+=dfs(cur*10+3,use | 0b100, counter)

    return counter

print(dfs(0,0,0))

Submission status: Accepted

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

if len(n) < 3 or int(n) <= 356:
  pass
else:
  num = "753"
  for x in range(3,len(n)+1):
    for y in itertools.product(num, repeat=x):
      if "7" in y and "5" in y and "3" in y:
        if int("".join(y)) <= int(n):
          ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

kz_ls = []
q_ls = ['3', '5', '7']
while True:
    if not q_ls:
        break
    else:
        tmp = q_ls.pop(0)
        kz_ls.append(tmp)
        if len(tmp) < 9:
            q_ls.append(tmp + '3')
            q_ls.append(tmp + '5')
            q_ls.append(tmp + '7')

kazus = []
for item in kz_ls:
    if item.count('3') > 0 and item.count('5') > 0 and item.count('7') > 0:
        kazus.append(int(item))

kazus.sort()

ret = 0
for item in kazus:
    if item <= n:
        ret += 1
print(ret)

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())

digit = len(str(n))

cnt = 0
for d in range(3, digit+1):
    gen = product(["7", "5", "3"], repeat=d)
    for gen_num in gen:
        s = "".join(gen_num)
        if "7" not in s:
            continue
        if "5" not in s:
            continue
        if "3" not in s:
            continue
        if int(s) > n:
            continue
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools
n = input()
number = list("753")
N = []
flag = False
for i in range(3, 10):
  for v in itertools.product(number, repeat=i):
    if "7" in v and "5" in v and "3" in v:
      if int("".join(v)) <= int(n): N.append(int("".join(v)))
print(len(N))

Submission status: Accepted

Solution code:
import copy
n = int(input())

bit = 0
n_sub = n
while n_sub > 0:
  bit += 1
  n_sub //= 10

index = 0
key = [(3, 1), (5, 2), (7, 3)]

for i in range(1, bit):
  last = len(key)
  for j in range(index, last):
    k1, k2 = key[j][0], key[j][1]
    if k2 == 1:
      key.append((k1*10+3, 1))
      key.append((k1*10+5, 4))
      key.append((k1*10+7, 5))
    if k2 == 2:
      key.append((k1*10+3, 4))
      key.append((k1*10+5, 2))
      key.append((k1*10+7, 6))
    if k2 == 3:
      key.append((k1*10+3, 5))
      key.append((k1*10+5, 6))
      key.append((k1*10+7, 3))
    if k2 == 4:
      key.append((k1*10+3, 4))
      key.append((k1*10+5, 4))
      key.append((k1*10+7, 7))
    if k2 == 5:
      key.append((k1*10+3, 5))
      key.append((k1*10+5, 7))
      key.append((k1*10+7, 5))
    if k2 == 6:
      key.append((k1*10+3, 7))
      key.append((k1*10+5, 6))
      key.append((k1*10+7, 6))
    if k2 == 7:
      key.append((k1*10+3, 7))
      key.append((k1*10+5, 7))
      key.append((k1*10+7, 7))
  index = last

ans = 0
for value in key:
  v1, v2 = value[0], value[1]
  if v2 == 7 and v1 <= n:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
def dfs(s): #sで始まる753数
    if int(s)>n:
        return 0
    ret = 1 if all(s.count(f) for f in "753") else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
# Problem C - 755

from collections import deque

# input
N = input()
n_keta = len(N)
N = int(N)

# initialization
class Search:
    def __init__(self, n, keta):
        self.ans = 0
        self.n = n
        self.keta = keta

    def get_ans(self):
        return self.ans

    def check_str(self, check_num, check_str):
        return check_num<=self.n and '3' in check_str and '5' in check_str and '7' in check_str

    # dfs search
    # num_str is deque
    def dfs(self, num_str):
        if len(num_str)==self.keta:
            check_num = int("".join(num_str))
            if self.check_str(check_num, num_str):
                self.ans += 1
        else:
            for s in ['3', '5', '7']:
                num_str.append(s)
                check_num = int("".join(num_str))
                if len(num_str)<self.keta:
                    if self.check_str(check_num, num_str):
                        self.ans += 1
                self.dfs(num_str)
                num_str.pop()

# calc
dfs_search = Search(N, n_keta)
num_str = deque([])
dfs_search.dfs(num_str)

# output
print(dfs_search.get_ans())

Submission status: Accepted

Solution code:

counter = 0
N = 0
def dfs(cur,use):
    global counter,N
    if(cur > N): return
    if(use == 7): counter += 1

    dfs(cur*10+7,use | 0b001)
    dfs(cur*10+5,use | 0b010)
    dfs(cur*10+3,use | 0b100)


def main():
    global N
    N = int(input())
    dfs(0,0)
    print(counter)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())

def func(cur,use):
    global res
    if cur>n:
        return
    if use==0b111:
        res+=1
    func(cur*10+7,use | 0b001)
    func(cur*10+5,use | 0b010)
    func(cur*10+3,use | 0b100)

res=0
func(0,0)
print(res)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(val, A):
	if val > n:
		return

	A.append(val)

	for v in [3, 5, 7]:
		dfs(10 * val + v, A)


A = []
for v in [3, 5, 7]:
	dfs(v, A)

cnt = 0
for v in A:
	if '3' in str(v) and '5' in str(v) and '7' in str(v):
		cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
A = set()
for x in product('753_', repeat=9):
    s = ''.join(x).replace('_', '')
    if all(d in s for d in '753') and int(s) <= n:
        A.add(s)
print(len(A))

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
A = set()
for x in product('753_', repeat=9):
    s = ''.join(x)
    s = s.replace('_', '')
    if '7' in s and '5' in s and '3' in s and int(s) <= n:
        A.add(s)
print(len(A))

Submission status: Accepted

Solution code:
def dfs(A, use, cnt):
    if A > n:
        return cnt
    if use == 0b111:
        cnt.append(1)

    dfs(A*10+7, use|0b100, cnt)
    dfs(A*10+5, use|0b010, cnt)
    dfs(A*10+3, use|0b001, cnt)

n = int(input())
ans = []
dfs(0, 0, ans)
print(len(ans))

Submission status: Accepted

Solution code:
import numpy as np
def enum753():
    table = str.maketrans({
        '0': '3',
        '1': '5',
        '2': '7'
    })
    ret = []
    for d in range(3, 10):
        for n in range(3 ** d):
            s = np.base_repr(n, 3).zfill(d).translate(table)
            if all(c in s for c in "357"):
                ret.append(int(s))
    return ret

print(np.searchsorted(enum753(), int(input()), side="right"))

Submission status: Accepted

Solution code:
n=int(input())
A=["3","5","7"]
A=set(A)
cnt=0

for _ in range(len(str(n))-1):
	for a in list(A):
		x=a+"3"
		y=a+"5"
		z=a+"7"
		if int(x)<=n:
			A.add(x)
		if int(y)<=n:
			A.add(y)
		if int(z)<=n:
			A.add(z)

res=0

for a in list(A):
	if "3" in a and "5" in a and "7" in a:
		res+=1		

print(res)

Submission status: Accepted

Solution code:
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)
	
n=int(input())
l=len(str(n))

res=0

for i in range(4**l):
	x=Base_10_to_n(i,4)
	cnt=0
	if not "0" in x: 
		if ("3" in x) and ("2" in x) and ("1" in x):
			for j in range(len(x)):
				if x[j]=="1":
					cnt+=3*(10**j)
				elif x[j]=="2":
					cnt+=5*(10**j)
				elif x[j]=="3":
					cnt+=7*(10**j)
			if cnt<=n:
				res+=1
			
print(res)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(a):
    if int(a) > n:
        return 0
    ret = 1 if all(a.count(c) > 0 for c in '753') else 0
    for v in '753':
        a += v
        ret += dfs(a)  # この3行を ret += dfs(a+v) とも書ける
        a = a[:-1]  # numはそのまま繰り返される
    return ret


print(dfs('0'))

Submission status: Accepted

Solution code:
n=int(input())
from collections import deque
kouho=["3","5","7"]
d=deque()
d.extend(kouho)
res=0
kk=0
while kk<=n:
  k=d.popleft()
  for x in kouho:
    a=k
    d.append(k+x)
  if not "3" in k:
    continue
  elif not "5" in k:
    continue
  elif not "7" in k:
    continue
  kk=int(k)
  if kk<=n:
    res+=1
  
  
print(res)

Submission status: Accepted

Solution code:
n=int(input())
import itertools as it
res=0
count=3
oo=""
while count<10:
  lis=list(it.product("375",repeat=count))
  for i in range(0,len(lis)):
    hahaha=lis[i]
    if not "3" in hahaha:
      continue
    elif not "5" in hahaha:
      continue
    elif not "7" in hahaha:
      continue
    hahaha=oo.join(hahaha)
    if int(hahaha)<=n:
      res+=1
  count+=1
print(res)

Submission status: Accepted

Solution code:
from itertools import product
from bisect import bisect_right

n = int(input())
m = len(str(n))

ans = 0
for i in range(3, m+1):
    candidates = []
    for v in product(['3', '5', '7'], repeat=i):
        if '3' in v and '5' in v and '7' in v:
            candidates.append(int(''.join(v)))
    candidates.sort()
    ans += bisect_right(candidates, n)

print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
digit = 3
ans = 0
while True:
    for t in itertools.product((3, 5, 7), repeat=digit):
        if set(t) != {3, 5, 7}:
            continue
        x = int(''.join(map(str, t)))
        if x > N:
            print(ans)
            exit()
        ans += 1
    digit += 1

Submission status: Accepted

Solution code:
N=int(input())
M=str(N)
L=len(M)
A=[[] for _ in range(L+1)]
A[0]=[""]

cnt=0
for i in range(1,L+1):
  for a in A[i-1]:
    b = a+"3"
    c=  a+"5"
    d=  a+"7"
    if int(b) <= N:
      A[i].append(b)
    if int(c) <= N:
      A[i].append(c)
    if int(d) <= N:
      A[i].append(d)
  for item in A[i]:
    if item.count("3")>=1 and item.count("5")>=1 and item.count("7")>=1:
      cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())
ret = 0
def func(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 += func(s+c)
    return ret
    
print(func('0'))

Submission status: Accepted

Solution code:
from collections import deque

n=int(input())
num=["3","5","7"]
a=deque([])
ans=0

def dfs():
  global ans
  if len(a)>0 and int("".join(a))>n:
    return
  if "3" in a and "5" in a and "7" in a:
    ans+=1
  for i in num:
    a.append(i)
    #print("a",a,"".join(a),"ans",ans)
    dfs()
    a.pop()
dfs()
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

    res = int(use == 0b111)
    res += dfs(value + "7", use | 0b001)
    res += dfs(value + "5", use | 0b010)
    res += dfs(value + "3", use | 0b100)

    return res

print(dfs("0", 0))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(value, use):
    if value > N:
        return 0

    res = int(use == 0b111)
    res += dfs(value * 10 + 7, use | 0b001)
    res += dfs(value * 10 + 5, use | 0b010)
    res += dfs(value * 10 + 3, use | 0b100)

    return res

print(dfs(0, 0))

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
def mask(i): return 1 << ((i-3) >> 1)
def dfs(a, use):
    global ans
    if a > n: return
    if use == 0b111: ans += 1
    for i in [3, 5, 7]: dfs(a*10+i, use | mask(i))

dfs(0, 0)
print(ans)

Submission status: Accepted

Solution code:
import sys
N = int(input())


sys.setrecursionlimit(1000000)

plist = []


def dfs(p):
    if len(set(p)) == 3:
        plist.append(int(''.join(map(str, p))))
    if len(p) == 9:
        return
    dfs(p+[3])
    dfs(p+[5])
    dfs(p+[7])


dfs([])

ans = 0
for p in plist:
    if int(p) <= N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

n_str = input()
n = int(n_str)
l = len(n_str)

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

ans = 0
for i in range(3, l + 1):
    for temp in list(product(e_list, repeat=i)):
        # print(temp)
        if "3" in temp and "5" in temp and "7" in temp:
            num = int("".join(temp))
            if num <= n:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
count = 0

def has_357(A):
    return '3' in A and '5' in A and '7' in A

def dfs(A):
    global count

    if A != '' and int(A) > N:
        return

    if has_357(A):
        count += 1

    for i in '357':
        A += i
        dfs(A)
        A = A[:-1]

    return count

print(dfs(''))

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:
import copy

n = int(input())


s = []
def dfs(A):
    if len(A) == len(str(n)):
        return
    for i in ['7', '5', '3']:
        A.append(i)
        if len(set(A)) == 3 and int(''.join(A)) <= n:
            s.append(int(''.join(A)))
        dfs(A)
        A.pop()

dfs([])

#print(s)
print(len(s))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque

base = ["3", "5", "7"]
N = int(input())
q = deque(base)
ans = 0
while q:
    num = q.pop()
    for i in base:
        next = num + i
        if int(next) <= N:
            q.append(next)
            if next.count("3") and next.count("5") and next.count("7"): 
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a1=["7","5","3"]
a2=[]
a3=[]
a4=[]
for i in range(len(str(n))-1):
    for j in range(len(a3)):
        a4.append(a3[j]+"3")
        a4.append(a3[j]+"5")
        a4.append(a3[j]+"7")
        a3.append(a3[j]+"3")
        a3.append(a3[j]+"5")
        a3[j]=a3[j]+"7"
    for j in range(len(a2)):
        if a2[j][1]=="3":
            a3.append(a2[j][0]+"3")
            a4.append(a2[j][0]+"3")
            a2.append([a2[j][0]+"5","3"])
            a2[j][0]=a2[j][0]+"7"
        if a2[j][1]=="5":
            a3.append(a2[j][0]+"5")
            a4.append(a2[j][0]+"5")
            a2.append([a2[j][0]+"7","5"])
            a2[j][0]=a2[j][0]+"3"
        if a2[j][1]=="7":
            a3.append(a2[j][0]+"7")
            a4.append(a2[j][0]+"7")
            a2.append([a2[j][0]+"5","7"])
            a2[j][0]=a2[j][0]+"3"
    for j in range(len(a1)):
        if a1[j][0]=="7":
            a2.append([a1[j]+"5","3"])
            a2.append([a1[j]+"3","5"])
            a1[j]=a1[j]+"7"
        if a1[j][0]=="5":
            
            a2.append([a1[j]+"7","3"])
            a2.append([a1[j]+"3","7"])
            a1[j]=a1[j]+"5"
        if a1[j][0]=="3":
            a2.append([a1[j]+"5","7"])
            a2.append([a1[j]+"7","5"])
            a1[j]=a1[j]+"3"
count=0
for i in reversed(range(0,len(a4))):
    if len(a4[i])<len(str(n)):
        break
    if int(a4[i])>n:
        count+=1
print(len(a4)-count)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
ans = 0

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

for i in range(3, 11):
    shichi_nums = itertools.product(shichigosan, repeat=i)
    for nums in shichi_nums:
        # print(nums)
        num = "".join(nums)
        if "3" in num and "5" in num and "7" in num:
            num = int(num)
            if num <= N:
                # print(num, ans)
                ans += 1
            else:
                print(ans)
                quit()

Submission status: Accepted

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


def solve(N: int):
    sN = str(N)
    ans = 0
    for i in range(1, len(sN) + 1):
        for p in product("357", repeat=i):
            if len(set(p)) == 3 and int("".join(p)) <= N:
                ans += 1
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()

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())
total = set()
def check(x):
    if x.count('7') and x.count('5') and x.count('3'):
        return True
    else:
        return False

def dfs(a):
    if len(a) > len(str(n)):
        return

    for i in ['7', '5', '3']:
        a += i
        if int(a) <= n and check(a):
            total.add(a)
        dfs(a)
        a = a[:-1]


dfs('')
print(len(total))

Submission status: Accepted

Solution code:
# C
import itertools
tmp = input()
siz = len(tmp)
N = int(tmp)

table = ['3','5','7']
cnt = 0 
for i in range(3, siz):
    #print("i", i)
    for combi in itertools.product(table, repeat=i):
        #print(combi)
        cnt += 1 if len(set(combi)) == 3 else 0

for combi in itertools.product(table, repeat=siz):
    # combiを数字に変換
    cur = 0
    for i,v in enumerate(combi[::-1]):
        cur += 10**i * int(v)
    #print(cur, combi)
    # Nと比較
    if N >= cur:
        cnt += 1 if len(set(combi)) == 3 else 0
        

print(cnt)

Submission status: Accepted

Solution code:
def dfs(A, B):
    if len(A) > len(str(n)):
        return
    for i in sft:
        A.append(i)
        if int("".join(A)) <= n and ("3" in A) and ("5" in A) and ("7" in A):
            B.append("".join(A))
        dfs(A,B)
        A.pop()

if __name__ == "__main__":
    n = int(input())
    num_list = []
    ans_list=[]
    sft = ["3", "5", "7"]
    dfs(num_list,ans_list)
    print(len(ans_list))

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    print(dfs("",N, [False,False,False]))

def dfs(num, N, include):
    cnt = 0
    digit = ['7','5','3']

    for i in range(len(digit)):
        next_num = num + digit[i]
        next_include = include[:]
        next_include[i] = True
        if int(next_num) <= N:
            if next_include == [True,True,True]:
                cnt += 1
            cnt += dfs(next_num,N, next_include)
    
    return cnt
    
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
c='753'
def dfs(s,L):
    global c
    li.append(s)
    if(len(s)==L):
        return
    for i in range(3):
        dfs(s+c[i],L)

N=int(input())
L=len(str(N))
li=[]
dfs('',L)
ans=0
for x in li:
    if(x==''):
        continue
    if(int(x)<=N and '7' in x and '5' in x and '3' in x):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:

N = int(input())

q = list("357")


def dfs(X):
    if int(''.join(X)) > N:
        return 0

    res = 0
    if set(X) == set(q):
        res = 1

    for i in q:
        X.append(i)
        res += dfs(X)
        X.pop()
    
    return res



res = 0
for i in range(len(q)):
    res += dfs(list(q[i]))

print(res)

Submission status: Accepted

Solution code:
n=int(input())
l=('3','5','7')
def dfs(a,ans):
    if len(a)>=2 and int(''.join(a[1:]))>n:
      return ans
    for i in l:
        a.append(i)
        if all(j in a for j in l) and  int(''.join(a[1:]))<=n:
          ans+=1
        ans+=dfs(a,0)
        a.pop()
    return ans
print(dfs([0],0))

Submission status: Accepted

Solution code:
N = int(input())


def dfs(A):
    if len(A)==len(str(N))+1:
        return 0
    
    cnt = 0
    if set(A) == set([3, 5, 7]):
            if int(''.join(map(str, A))) <= N:
#                 print(A)
                cnt = 1
                
    for i in [3, 5, 7]:
        A.append(i)
        cnt += dfs(A)
        A.pop()
    return cnt

cnt = 0
ans = dfs([])
print(ans)

Submission status: Accepted

Solution code:
def dfs(a):
    global ans
    if a>n:
        return
    if len(set(list(str(a))))==3:
        ans+=1
    for i in (3,5,7):
        a=a*10+i
        dfs(a)
        a//=10
    
n=int(input())
ans=0
dfs(0)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import*
n = int(input())
c = 0
k = "357"

for i in range(3, -~len(str(n))):
    for j in product(k, repeat = i):
        if all(j.count(h) for h in k):
            if int("".join(j)) <= n:
                c += 1
print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())

def dfs(k):  # k : str
    if int(k) > n: return 0
    c = 1 if all(k.count(t) for t in "753") else 0  # k judge
    for t in "753":
        c += dfs(k + t)
    return c
print(dfs("0"))

Submission status: Accepted

Solution code:
def func(cur, use):
  
  global counter
  if (cur > N): return 
  if (use == 0b111): counter += 1

  func(cur * 10 + 7, use | 0b001)
  func(cur * 10 + 5, use | 0b010)
  func(cur * 10 + 3, use | 0b100) 

N = int(input())
counter = 0
func(0, 0)
print(counter)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
M = [3, 5, 7]
num = []
def dfs(A):
    if A == "":
        pass    
    elif int(A) > N:
        return
    else:
        num.append(A)
    for v in M:
        A = A + str(v)
        dfs(A)
        A = A[:-1]
               
dfs("")
ans = []
for i in num:
    if len(Counter(i)) == 3:
        ans.append(i)
print(len(ans))

Submission status: Accepted

Solution code:
N = int(input())
M = len(str(N))
count = 0

def dfs(A):
  global count
  
  if len(A) <= M and (3 in A and 5 in A and 7 in A):
    num = 0
    for i in range(len(A)):
      num += A[i]*(10**i)
    if num <= N:
      count += 1
  elif len(A) > M:
    return

  for i in [3, 5, 7]:
    A.append(i)
    dfs(A)
    A.pop()
  
dfs([])
print(count)

Submission status: Accepted

Solution code:
n = input()
def dfs(A):
    #print(A)
    global cnt
    if len(A) > len(n):
        return
    if len(A) >= 3 and int(A) <= int(n):
        if A.count('7') >= 1 and A.count('5') >= 1 and A.count('3') >= 1:
            cnt += 1
            #print('?')
    for num in "357":
        A += num
        dfs(A)
        A = A[:-1]

cnt = 0
dfs("")
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

def isOK(s):
    t = (''.join(s))
    if int(t) > n: return False
    f = True
    for i in [7, 5, 3]:
        if not str(i) in t: f = False
    return f

def dfs(s, res):
    if len(s) > 0 and int(''.join(s)) > n:
        return res
    for i in [3, 5, 7]:
        s.append(str(i))
        if isOK(s): res+=1
        res += dfs(s, 0)
        s.pop()
    return res
print(dfs([], 0))

Submission status: Accepted

Solution code:
n = int(input())

def dfs(l):
    return sum([
        # next
        dfs(10 * l + i) if (10 * l + i) <= n else 0
        for i in [3, 5, 7]] +
        # current
        [1 if '3' in str(l) and '5' in str(l) and '7' in str(l) else 0]
        )

print(dfs(0))

Submission status: Accepted

Solution code:
n = int(input())
q = [ 3, 5, 7 ]

ans = 0
while len(q) != 0:
    x = q.pop(0)
    for i in [ 3, 5 , 7]:
        y = 10 * x + i
        if ( y <= n):
            q.append(y)
            if '3' in str(y) and '5' in str(y) and '7' in str(y):
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s, res):
  if int(s) > N:
    return 0
  res = +all((t in s)for t in '753')
  for i in '753':
    res += dfs(s+i, res)
  return res

print(dfs('0', 0))

Submission status: Accepted

Solution code:
N = int(input())

l = len(str(10**9))
def dfs(A):#配列Aからできる753数
    global N
    if len(A)>0 and(int("".join(map(str, A)))>N):
        return 0
    
    ans = 0
    if(all(A.count(i)==0 for i in [0, 1, 2, 4, 6, 8, 9]) and (A.count(3) >0 and A.count(5) >0 and A.count(7) >0)):
        ans = ans + 1
    
    for i in [3, 5, 7]:
        A.append(i)
        ans = ans + dfs(A)
        A.pop()
    
    return ans
print(dfs([]))