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

keta=len(str(n))
hako=[]
for i in range(3,keta+1):
    for c in list(itertools.product(["7","5","3"],repeat=i)):
        if len(set(c))==3:
            a=int("".join(c))
            hako.append(a)
if n in hako:
    hako.sort()
    k=hako.index(n)
    b=hako[:k]
    print(len(b)+1) 
else:
    hako.append(n)
    hako.sort()
    k=hako.index(n)
    b=hako[:k]
    print(int(len(b)))

Submission status: Accepted

Solution code:
def main():
	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"))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def check(x):
    str_x = str(x)
    if min(str_x.count("3"),str_x.count("5"),str_x.count("7")) > 0:
        return True
    else:
        return False

def solve(x):
    if x > N:
        return 0
    if check(x):
        ans = 1
    else :
        ans = 0
    ans += solve(10*x + 3)
    ans += solve(10*x + 5)
    ans += solve(10*x + 7)
    return ans
N = int(input())
print(solve(0))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(x):
    if x > N:
        return 0

    san, go, nana = 0, 0, 0
    c = x
    for i in range(len(str(c))):
        if c % 10 == 3:
            san += 1
        elif c % 10 == 5:
            go += 1
        elif c % 10 == 7:
            nana += 1
        c = c // 10
    if san > 0 and go > 0 and nana > 0:
        ret = 1
    else:
        ret = 0

    for i in [3, 5, 7]:
        ret += dfs(10*x + 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:
from itertools import product
n = int(input())
cnt = 0
for i in range(3, len(str(n))+1):
	for p in product(["7","5","3"], repeat = i):
		if len(set(p)) == 3:
			p = int("".join(p))
			if p <= n:
				cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
num = ["","3","5","7"]
A = set() 
for i in product(num,repeat=9):
	x = "".join(i)
	if x == "":
		continue
	elif len(set(x)) < 3:
		continue
	elif int(x) not in A and int(x) <= n:
		A.add(int(x))
print(len(A))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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:
# -*- coding: utf-8 -*-

n = input()
digit = len(n)
n = int(n)

def make753(num):
    cand = [""]
    endj = 0
    for i in range(num):
        for j in range(endj,3 ** i + endj):
            cand.append(cand[j] + "7")
            cand.append(cand[j] + "5")
            cand.append(cand[j] + "3")
            endj = j + 1
    del cand[0]
    return cand

cand = make753(digit)

delete = []
for i in range(len(cand)):
    if "3" not in cand[i] or "5" not in cand[i] or "7" not in cand[i]:
        delete.append(i)

diff = 0
for i in range(len(delete)):
    del cand[delete[i] - diff]
    diff += 1

for i in range(len(cand)):
    cand[i] = int(cand[i])

cand.sort()

for i in range(len(cand)):
    if n < cand[i]:
        print(i)
        break
else:
    print(len(cand))

Submission status: Accepted

Solution code:
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:
N = int(input())
res = 0
def is753(N):
    n7,n5,n3 = 0,0,0
    while N > 0:
      if N % 10 == 7:
          n7 = 1
      elif N%10 == 5:
          n5 = 1
      else:
          n3 = 1
      N = N // 10
    return n5 & n3 & n7

def solve(D):
	if D > N:
		return 0
	else:
		d = 0
		if is753(D):
			d = 1
		return solve(D*10+3) +  solve(D*10+5) + solve(D*10+7) + d
print(solve(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) 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(s):
    global ans
    if int(s) > N:
        return

    if all(s.count(c) for c in '753'):
        ans += 1
    
    dfs(s + '7')
    dfs(s + '5')
    dfs(s + '3')

dfs('0')

print(ans)

Submission status: Accepted

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

def dfs(s):
    global ans
    if int(s) > N:
        return

    if s.count('7') and s.count('5') and s.count('3'):
        ans += 1
    
    dfs(s + '7')
    dfs(s + '5')
    dfs(s + '3')

dfs('0')

print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

count = 0
for n in range(3, 10):
    for p in itertools.product(['3', '5', '7'], repeat=n):
        pstr = ''.join(p)
        if len(set(pstr)) < 3 or int(pstr) > N:
            continue
        count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
def calc(t):
    if int(t) > n:
        return 0
    if (("3" in t) & ("5" in t) & ("7" in t)):
        ret = 1
    else:
        ret = 0
    for c in "357":
        ret += calc(t+c)
    return ret

print(calc("0"))

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
ans = 0
for l in range(1, 11):
    for p in product("357", repeat=l):
        v = "".join(p)
        if "3" in v and "5" in v and "7" in v and int("".join(p)) <= N:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def f753():
    s=["3","5","5"]
    while 1:
        lens=len(s)
        for i in range(lens-1,-1,-1):
            if s[i]!="7":
                s[i]="5" if s[i]=="3" else "7"
                for ii in range(i+1,lens):
                    s[ii]="3"
                break
        else:
            s=["3"]*(lens-1)+["5","7"]
        if len(set(s))<3:continue
        yield int("".join(s))

n=int(input())
cnt=0
for n753 in f753():
    if n753>n:break
    cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
N=int(input())

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

print(cal("3")+cal("5")+cal("7"))

Submission status: Accepted

Solution code:
import math
from itertools import product
import sys
input = sys.stdin.readline

N = int(input())
ans = 0

for j in range(3, int(math.log10(N))+2):
    list753 = [['3', '5', '7'] for _ in range(j)]
    for i in product(*list753):
        if ('3' in i) and ('5' in i) and ('7' in i) and int(''.join(i)) <= N:
            ans += 1
        else:
            continue

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
def dfs(scgs):
    # 終了の処理 dfs(scgs)=0
    if int(scgs) > N:
        return 0
    # scgsが753数かどうか
    if all(scgs.count(c)>0 for c in '753'):
        ret = 1
    else:
        ret = 0
    # 分岐処理
    for c in '753':
        ret = ret + dfs(scgs + c)
    return ret
print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())
nums = []
length = len(str(N))
def dfs(s, n):
        global nums
        nums.append(s)
        if n == length:
                return
        dfs(s + "3", n + 1)
        dfs(s + "5", n + 1)
        dfs(s + "7", n + 1)

dfs("", 0)
ans = 0
for i in nums:
        if i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1:
                if int(i) <= N:
                        ans += 1
print(ans)

Submission status: Accepted

Solution code:
count = 0
N = 0
def make753num(num):
    global count
    global N
    if num > N:
        return
    if num >= 357 and min(str(num).count('3'), str(num).count('5'), str(num).count('7')) >= 1:
        count += 1
    make753num(num * 10 + 3)
    make753num(num * 10 + 5)
    make753num(num * 10 + 7)
def main():
    global count
    global N
    N = int(input())
    make753num(0)
    print(count)
main()

Submission status: Accepted

Solution code:
N = int(input())
L = ['3','5','7']
K = str(N)
for i in range(len(K)):
  T = len(L)
  for j in range(T):
    L.append(L[j]+'3')
    L.append(L[j]+'5')
    L.append(L[j]+'7')
  L = list(set(L))
ans = 0
for i in range(len(L)):
  cnt3 = 0
  cnt5 = 0
  cnt7 = 0
  for j in range(len(L[i])):
    if L[i][j] == '3':
      cnt3 += 1
    elif L[i][j] == '5':
      cnt5 += 1
    else:
      cnt7 += 1
  if cnt3 > 0 and cnt5 > 0 and cnt7 > 0:
    if int(L[i]) <= N:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
N = input()
length = len(N)
T = [''.join(t) for t in product(('3','5','7'),repeat = 3)]

def f(N,s):
    if len(s) == length:
        if int(s) <= int(N) and '3' in s and '5' in s and '7' in s:
            return 1
        else:
            return 0
    else:
        if '3' in s and '5' in s and '7' in s:
            a = 1
        else:
            a = 0
        a += sum(f(N,s+c) for c in('3','5','7'))
        return a
if int(N)<357:
    print(0)
else:
    print(sum(f(N, t) for t in T))

Submission status: Accepted

Solution code:
N = int(input())  # 数値入力


def dfs(s):
    # 潜りすぎ防止
    if int(s) > N:
        return 0

    # 7,5,33がすべて含まれていたらret=1
    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):
  if int(s)>n:
    return 0
  if all(s.count(i)>0 for i in '753'):
    ans=1
  else:
    ans=0
  for i in '753':
    ans+=dfs(s+i)
  return ans
print(dfs('0'))

Submission status: Accepted

Solution code:
import itertools

n_str = input()
n = int(n_str)
digits = len(n_str)
nums = ('3', '5', '7')
count = 0
for i in range(3, digits + 1):
    for strs in itertools.product(*[nums]*i):
        m = int(''.join(strs))
        if ('3' in strs) and ('5' in strs) and ('7' in strs) and m <= n:
            count += 1
print(count)

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('')と書きたいがint(s)でエラーを吐かないように仕方なく

Submission status: Accepted

Solution code:
import numpy as np
from itertools import product
s = input()
n = int(s)

digit = len(s)

selected_num = []
for order in range(3, 10, 1):
    for i in product('753', repeat = order):
        concat_str = "".join(i)
        if(('7' in concat_str) and ('5' in concat_str) and ('3' in concat_str)): 
            selected_num.append(int(concat_str))

selected_num_array = np.array(selected_num)

print(np.sum(selected_num_array <= 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:
n=int(input())
def dfs(s):
  if int(s)>n:
    return 0
  ret = 1 if all(s.count(c) for c in "753") else 0
  for c in '753':
    ret+=dfs(s+c)
  return ret
print(dfs("0"))

Submission status: Accepted

Solution code:
n=int(input())
s=[]
def dfs(string,cur):
  if cur==len(str(n)):
    if string.count('3')>0 and string.count('5')>0 and string.count('7'):
      s.append(string)
    return
  dfs(string+"",cur+1)
  dfs(string+"7",cur+1)
  dfs(string+"5",cur+1)
  dfs(string+"3",cur+1)
dfs("",0)

cnt=0
for i in set(s):
  if int(i)<=n:
    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(c in s 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):
    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:
from itertools import product
N = int(input())
cnt = 0
for i in range(3, len(str(N))+1):
  for p in product(["7", "5", "3"], repeat = i):
    if "7" in p and "5" in p and "3" in p:
      p = int("".join(p))
      if p <= N:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
cnt = 0
for i in range(3, len(str(N))+1):
    for p in product(["7", "5", "3"], repeat = i):
        if "7" in p and "5" in p and "3" in p:
            p = int("".join(p))
            if p <= N:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
cnt = 0
for i in range(3, len(str(N))+1):
    for p in product(["7", "5", "3"], repeat = i):
        if "7" in p and "5" in p and "3" in p:
            n = int("".join(p))
            if n <= N:
                cnt += 1
print(cnt)

Submission status: Accepted

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

ans = 0

for i in sftnum:
    for j in sftnum:
        for k in sftnum:
            for ii in sftnum:
                for jj in sftnum:
                    for kk in sftnum:
                        for iii in sftnum:
                            for jjj in sftnum:
                                for kkk in sftnum:
                                    num = i*100000000+j*10000000+k*1000000+ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                                    if num > n:
                                        break
                                    elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                                        ans = ans +1

for j in sftnum:
    for k in sftnum:
        for ii in sftnum:
            for jj in sftnum:
                for kk in sftnum:
                    for iii in sftnum:
                        for jjj in sftnum:
                            for kkk in sftnum:
                                num = j*10000000+k*1000000+ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                                if num > n:
                                    break
                                elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                                    ans = ans +1

for k in sftnum:
    for ii in sftnum:
        for jj in sftnum:
            for kk in sftnum:
                for iii in sftnum:
                    for jjj in sftnum:
                        for kkk in sftnum:
                            num = k*1000000+ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                            if num > n:
                                break
                            elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                                ans = ans +1


for ii in sftnum:
    for jj in sftnum:
        for kk in sftnum:
            for iii in sftnum:
                for jjj in sftnum:
                    for kkk in sftnum:
                        num = ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                        if num > n:
                            break
                        elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                            ans = ans +1

for jj in sftnum:
    for kk in sftnum:
        for iii in sftnum:
            for jjj in sftnum:
                for kkk in sftnum:
                    num = jj*10000+kk*1000+iii*100+jjj*10+kkk
                    if num > n:
                        break
                    elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                        ans = ans +1

for kk in sftnum:
    for iii in sftnum:
        for jjj in sftnum:
            for kkk in sftnum:
                num = kk*1000+iii*100+jjj*10+kkk
                if num > n:
                    break
                elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                    ans = ans +1

for iii in sftnum:
    for jjj in sftnum:
        for kkk in sftnum:
            num = iii*100+jjj*10+kkk
            if num > n:
                break
            elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                ans = ans +1

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
N = ""


def set_inputs():
    global N
    N = get_str()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    n = int(N)
    ans = 0
    candidates = []
    for i in range(3, len(N)+1):
        candidates.extend(itertools.product([3, 5, 7], repeat=i))
    for c in candidates:
        if 3 in c and 5 in c and 7 in c:
            v = sum(map(lambda x: x[1] * (10 ** x[0]), enumerate(reversed(c))))
            if v <= n:
                ans += 1
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


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


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())

ans = 0
def dfs(s, target):
  global ans
  target = target + s

  if int(target) > N:
    return False

  if target.count("3") >= 1 and target.count("5") >= 1 and target.count("7") >= 1:
    ans += 1
  
  if dfs("3", target):
    return True
  
  if dfs("5", target):
    return True
  
  if dfs("7", target):
    return True
  
  
dfs("0" ,'')
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

ans = 0
def dfs(s, sum):
  global ans
  sum = sum + s


  if int(sum) > N:
    return False

  sum = str(int(sum))
  if sum.count("3") >= 1 and sum.count("5") >= 1 and sum.count("7") >= 1:
    ans += 1
  
  if dfs("3", sum):
    return True
  
  if dfs("5", sum):
    return True
  
  if dfs("7", sum):
    return True
  
  
dfs("0" ,'')
print(ans)

Submission status: Accepted

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

for k in range(1,10):
    s = itertools.product(["3","5","7"], repeat=k)
    for seq in s:
        x = set()
        for i in seq:
            x.add(i)
        if len(x) != 3:
            continue
        t = "".join(seq)
        if 1 <= int(t) <= n:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())


def count753(number):

    if int(number) > N:
        return 0

    if number == '0':
        number = ''

    if '7' not in number or '5' not in number or '3' not in number:
        result = 0
    else:
        result = 1

    result += count753('7' + number)
    result += count753('5' + number)
    result += count753('3' + number)

    return result


print(count753('0'))

Submission status: Accepted

Solution code:
from itertools import product

N = input()
l1 = ['3','5','7']

P = []
for i in range(len(N)):
  P += list(product(l1, repeat=i+1))

N = int(N)
ans = 0
for p in P:
  if ('7' not in p) or ('5' not in p) or ('3' not in p):
    continue
  else:
    p = int(''.join(p))
    ans += (p <= N)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())


def dfs(s):
    if int(s) > n:
        return 0
    # 7，5，3がすべて文字列に少なくとも一つ含まれていればOK
    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):
  if int(s)>N:
    return 0
  if s.count("3")>=1 and s.count("5")>=1 and s.count("7")>=1:
    ans=1
  else:
    ans=0
  for c in "753":
    ans+=dfs(s+c)
  return ans
print(dfs("0"))

Submission status: Accepted

Solution code:
n=int(input())
x=[0,3,5,7]
p=[]
flag=True
flag2=True
for c1 in x:
  for c2 in x:
    for c3 in x:
      for c4 in x:
        for c5 in x:
          for c6 in x:
            for c7 in x:
              for c8 in x:
                for c9 in x:
                  line=[c1,c2,c3,c4,c5,c6,c7,c8,c9]
                  sum_=0
                  if line.count(7)>0 and line.count(3)>0 and line.count(5)>0:
                    for i in range(9):
                      if flag==False and line[i] in [3,5,7]:
                        flag2=False
                        break
                      if line[i]==0:
                        flag=False
                      sum_+=line[i]*10**i
                    if flag2==False:
                      flag=True
                      flag2=True
                      continue
                    p.append(sum_)
                    flag=True
p.sort()
for i in range(len(p)):
  if p[i]>n:
    print(i)
    exit()
print(i+1)

Submission status: Accepted

Solution code:
import math
def rec(A, s, d, f):
    if d == f:
        return
    A.append(s)
    rec(A, s + "3", d+1, f)
    rec(A, s + "5", d+1, f)
    rec(A, s + "7", d+1, f)

N = int(input())
digit = int(math.log10(N)) + 1
A = []
rec(A, "", 0, digit+1)
Asize = len(A)
cnt = 0
for i in range(Asize):
    if "3" in A[i] and "5" in A[i] and "7" in A[i] and int(A[i]) <= N:
        cnt += 1
print(str(cnt))

Submission status: Accepted

Solution code:
#coding: utf-8
from collections import Counter
N = int(input())
l = ["0", "3", "5", "7"]
ans = ["0" for _ in range(9)]
cnt = 0
for a in l:
    ans[0] = a
    for b in l:
        ans[1] = b
        for c in l:
            ans[2] = c
            for d in l:
                ans[3] = d
                for e in l:
                    ans[4] = e
                    for f in l:
                        ans[5] = f
                        for g in l:
                            ans[6] = g
                            for h in l:
                                ans[7] = h
                                for i in l:
                                    ans[8] = i
                                    ans_i = int("".join(ans))
                                    ans_c = Counter(str(ans_i))
                                    if ans_i <= N and "0" not in str(ans_i) and len(ans_c.keys()) == 3 and len(str(ans_i)) >= 3:
                                        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())

cnt = 0
for i in range(3, len(str(N))+1):
  for p in product(["7", "5", "3"], repeat = i):
    if "7" in p and "5" in p and "3" in p:
      p = int("".join(p))
      if p <= N:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from sys import exit
# A,B,C = [int(n) for n in input().split()]
N = int(input())
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()

three = ['357', '375', '537', '573', '735', '753']
cand = ['3' , '5' , '7']
ans = 0
s = set()
def rladd(cur):
    global ans,N,s
    if(int(cur) > N) or cur in s: return False
    s.add(cur)
    ans+=1
    for i in range(len(cur)):
        for c in cand:
            temp = list(cur)
            temp.insert(i,c)
            rladd("".join(temp))
for th in three:
    rladd(th)

print(ans)

Submission status: Accepted

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

def dfs(i):
    global ans
    if int(i) > N:
        return
    if all(i.count(c) for c in '753'):
        ans += 1
    dfs(i + '3')
    dfs(i + '5')
    dfs(i + '7')
    
dfs('0')

print(ans)

Submission status: Accepted

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

if N < 357:
    print(0)
else:
    dig = int(math.log10(N)) + 1
    number = [[0] * dig for i in range(3**dig)]
    num = ['3','5','7']
    ans = 0

    for i in range(dig):
        for j in range(3**dig):
            number[j][-i-1] = num[int((j/(3**i))%3)]
    
    i = 0
    while i < len(number):
        if '3' not in number[i] or '5' not in number[i] or '7' not in number[i]: 
            number.pop(i)
        else:
            number[i] = int(''.join(number[i]))
            if N < number[i]:
                break
            i += 1

    for j in range(3,dig):
        ans += 3**j - 3 * (2**j) + 3
    print(ans+i)

Submission status: Accepted

Solution code:
def create_table(m, n=[], result=[]):
    if n and int(''.join(map(str,n))) > m: return result
    r = [3, 5, 7]
    if 3 in n and 7 in n and 5 in n: result.append(n)
    for x in r:
        create_table(m, n+[x], result)
    return result

n = int(input())
print(len(create_table(n)))

Submission status: Accepted

Solution code:
num = int(input())
def to3(x,n):
  if (int(x/n)):
    return to3(int(x/n),n) + str(x%n)
  return str(x%n)
ch = ["3","5","7"]
ans = 0
for i in range(3 ** len(str(num))+1):
  s = to3(i,3)
  for u in range(len(str(num))-len(s)+2):
    if u > 0:
      s = "0" + s
    k1 = 0
    k2 = 0
    k3 = 0
    ss = ""
    for j in range(len(s)):
      if s[j] == "0":k1 = 1
      elif s[j] == "1":k2 = 1
      else: k3 = 1
      ss += ch[int(s[j])]
    if k1 and k2 and k3 and int(ss) <= num:ans += 1
print(ans)

Submission status: Accepted

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

answer = 0
for n in range(1,10):
  for l in itertools.product(['7','3','5'], repeat=n):
    if '7' in l and '5' in l and '3' in l:
      answer += (int(''.join(l))<=N)

print(answer)

Submission status: Accepted

Solution code:
N = int(input())
L1 = ['3', '5', '7']
L2 = ['3', '5', '7']
for i in range(1, 9):
    for x in L2:
        if len(x) == i:
            for y in L1:
                L2.append(''.join([x, y]))
L2 = [int(x) for x in L2 if '3' in x and '5' in x and '7' in x]
L3 = [1 for x in L2 if x <= N]
print(len(L3))

Submission status: Accepted

Solution code:
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:
import itertools

N = input()
N1 = int(N)
N2 = len(N)

num753_comb = []
for i in range(N2):
  num753_comb.append([0,3,5,7])
All_comb = list(itertools.product(*num753_comb))

count = 0
for i in range(len(All_comb)):
 tmp = list(All_comb[i])
 tmp_num = 0
 judge0,judge3,judge5,judge7 = 0,0,0,0

 for j in range(N2):
   tmp_num += tmp[j]*(10**(N2-1-j))   
   if((tmp_num > 0)and(tmp[j] == 0)): judge0 += 1
   elif(tmp[j] == 3): judge3 += 1
   elif(tmp[j] == 5): judge5 += 1
   elif(tmp[j] == 7): judge7 += 1
   
 if(tmp_num <= N1):
   if((judge3>=1)and(judge5>=1)and(judge7>=1)and(judge0 == 0)):
      count += 1     
print(count)

Submission status: Accepted

Solution code:
c = ["3","5","7"]
sl = {"3","5","7"}
def cal(n):
    f   = True
    while f:
        cnt =0
        sl_c = sl.copy()
        for i in sl_c:
            if int(i) > n:
                f = False
            elif "3" in i and "5"  in i and "7" in i :
                #print(i)
                cnt+=1
            for j in c:
                sl.add(i+j)
    return cnt
n  = int(input())
print(cal(n))

Submission status: Accepted

Solution code:
N = int(input())
l = ['3','5','7']

def dfs(s):
    if int(s)>N:
        return 0
    res = sum([dfs(s+c) for c in l])
    if all([1 if c in s else 0 for c in l]):
        res += 1
    return res

print(dfs('0'))

Submission status: Accepted

Solution code:
import itertools
import numpy as np
N = input()
digit = len(N)
ans = 0
if int(N) < 357:
    print(ans)
else:
    for i in range(3, len(N)):
        ans += 3**i - 3 * 2**i + 3
    for v in itertools.product('753', repeat=digit):
        if (len(set(list(v)))==3) & (int(''.join(list(v))) <= int(N)):
            ans +=1
    print(ans)

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

def s_inpl(): return map(int,input().split())
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:
N = int(input())

digit_N = len(str(N))

def make_753(a,N_limit,n=None):
    if n==None:
        n = len(str(max(a)))
    tmp = 10 ** n
    return [tmp*3 + i for i in a if tmp*3+i <= N_limit] + \
            [tmp*5 + i for i in a if tmp*5+i <= N_limit] + \
            [tmp*7 + i for i in a if tmp*7+i <= N_limit]

list_753 = [[3,5,7] for _ in range(digit_N)]
for i in range(1,digit_N):
    list_753[i] = make_753(list_753[i-1],N,i)

def check_753(num):
    check_3 = 0
    check_5 = 0
    check_7 = 0
    num = str(num)
    for c in num:
        if check_3 == 0 and c == "3":
            check_3 = 1
        elif check_5 == 0 and c == "5":
            check_5 = 1
        elif check_7 == 0 and c == "7":
            check_7 = 1
    return check_3 * check_5 * check_7

out = 0
for tmp in list_753[2:]:
    for num in tmp:
        out += check_753(num)
print(out)