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: Wrong Answer

Solution code:
import math
def is_753(s) :
	
	if ("0" in s) :
		return False
	elif ("1" in s) :
		return False
	elif ("2" in s) :
		return False
	elif ("4" in s) :
		return False
	elif ("6" in s) :
		return False
	elif ("8" in s) :
		return False
	elif ("9" in s) :
		return False
	
	if ("7" in s and "5" in s and "3" in s) :
		return True
	
	return False

def main() :
	N = int(input())
	count = 0
	index = 357
	
	if (N < 357) :
		print("0")
		return

	while index < N :
		s = str(index)
		if (s[0] != "3" and s[0] != "5" and s[0] != "7" ) :
			index += int(math.pow(10, len(s)-1))
			continue
		elif (s[1] != "3" and s[1] != "5" and s[1] != "7" ) :
			index += int(math.pow(10, len(s)-2))
			continue
		elif (s[2] != "3" and s[2] != "5" and s[2] != "7" ) :
			index += int(math.pow(10, len(s)-3))
			continue
		elif (len(s) > 3 and s[3] != "3" and s[3] != "5" and s[3] != "7" ) :
			index += int(math.pow(10, len(s)-4))
			continue
		elif (len(s) > 4 and s[4] != "3" and s[4] != "5" and s[4] != "7" ) :
			index += int(math.pow(10, len(s)-5))
			continue
		elif (len(s) > 5 and s[5] != "3" and s[5] != "5" and s[5] != "7" ) :
			index += int(math.pow(10, len(s)-6))
			continue
		elif (len(s) > 6 and s[6] != "3" and s[6] != "5" and s[6] != "7" ) :
			index += int(math.pow(10, len(s)-7))
			continue
		elif (len(s) > 7 and s[7] != "3" and s[7] != "5" and s[7] != "7" ) :
			index += int(math.pow(10, len(s)-8))
			continue
		elif (len(s) > 8 and s[8] != "3" and s[8] != "5" and s[8] != "7" ) :
			index += int(math.pow(10, len(s)-9))
			continue
		elif (len(s) > 9 and s[9] != "3" and s[9] != "5" and s[9] != "7" ) :
			index += int(math.pow(10, len(s)-10))
			continue

		if (is_753(s)) :
			count += 1
		
		index += 1
	
	print(count)


main()

Submission status: Wrong Answer

Solution code:
n=int(input())

#base=["357","375","537","573","735","753"]
arr=["3","5","7"]
for i in range(9):
    t_arr=[]
    for i in arr:
        t_arr.append("3"+i)
        t_arr.append("5"+i)
        t_arr.append("7"+i)
    arr.extend(t_arr)
#print(len(arr))

count=0
for i in set(arr):
    if n>int(i) and "3" in i and "5" in i and "7" in i:
        count+=1
        #print(i)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

#print(list(str(n)))
answer = 0

sgs = set(['7', '5', '3'])

for i in range(357, n):
    s = list(str(i))
    if set(s) == sgs:
        answer += 1

print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  2 17:39:56 2018
ABC114C
@author: maezawa
"""
import itertools as itr
import bisect
n = int(input())

arr = []
for n_order in range(3,10):
    for a in itr.product([3,5,7], repeat=n_order):
        if 7 in a:
            if 5 in a:
                if 3 in a:
                    n753=0
                    for l in range(n_order):
                        n753+=10**l*a[l]
                    arr.append(n753)
arr.sort()

ans = bisect.bisect_left(arr,n)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n = input()

if len(n) < 3:
    exit()
cnt = 0
for i in range(3, len(n)+1):
    c = list(itertools.product(["3", "5", "7"], repeat=i))
    for num in c:
        if int(n) >= int("".join(num)) and (num.count("3") >=1
                and num.count("5") >= 1 and num.count("7") >= 1):
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())

cnt = 0
i = 1
while i < n:
    is_broken = False
    string = list(str(i))
    for j, s in enumerate(string[::-1]):
        if s not in ['3', '5', '7']:
            length = len(s)
            i = i + 10**j
            is_broken = True
            break
    if is_broken:
        continue

    c1 = string.count('3') >= 1
    c2 = string.count('5') >= 1
    c3 = string.count('7') >= 1
    if c1 and c2 and c3:
        cnt += 1

    if is_broken is False:
        i += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

def rec(p, ptn, ans):
    if len(ptn) > 0 and int(ptn) < int(N) and '3' in ptn and '5' in ptn and '7' in ptn:
        ans[0] += 1

    if p >= len(str(N)):
        return
    else:
        for n in ('3', '5', '7'):
            ptn += n
            rec(p+1, ptn, ans)
            ptn = ptn[:-1]

ans = [0]
rec(0, "", ans)

print(ans[0])

Submission status: Wrong Answer

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

import time

N = int(input())

all_num_list = []
nums = ["3", "5", "7"]

print(all_num_list)

for a in nums:
    for b in nums:
        for c in nums:
            all_num_list.append(a+b+c)
            for d in nums:
                all_num_list.append(a+b+c+d)
                for e in nums:
                    all_num_list.append(a+b+c+d+e)
                    for f in nums:
                        all_num_list.append(a+b+c+d+e+f)
                        for g in nums:
                            all_num_list.append(a + b + c + d + e + f+g)
                            for h in nums:
                                all_num_list.append(a + b + c + d + e + f + g+h)
                                for i in nums:
                                    all_num_list.append(a+b+c+d+e+f+g+h+i)

cnt = 0
for num in all_num_list:
    if int(num) <= N and "3" in num and "5" in num and "7" in num:
        print(num)
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
s = int(input())
cnt = 0
for i in range(s):
    if set(list(str(i))) == set(['3', '5', '7']):
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
count = 0
for i in range(n):
    str_n = str(n)
    str_n.replace("7", "").replace("5", "").replace("3", "")
    if not str_n:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
for i in range(1,n):
    stringi = str(i)
    isSeven = False
    isFive = False
    isThree = False
    iselse = False
    for s in stringi:
        if s == "7":
            isSeven = True
        elif s == "5":
            isFive = True
        elif s == "3":
            isThree = True
        else:
            iselse = True
            break
    if isSeven == True and isFive == True and isThree == True and iselse == False:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

count = 0
if N >= 357:
    for i in range(357,N,2):
        flag = 0
        flag7 = 0
        flag5 = 0
        flag3 = 0
        for s in str(i):
            if s != "7" and s != "5" and s != "3":
                flag = 1
                break
            if s == "7":
                flag7 = 1
            elif s == "5":
                flag5 = 1
            elif s == "3":
                flag3 = 1
        if flag == 0 and flag7 == 1 and flag5 == 1 and flag3 == 1:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:

inn = int(input())

result = 0

if inn < 357:
    print(0)

else:
    for i in range(357, inn):

        str_i = str(i)

        if '3' in str_i and '5' in str_i and '7' in str_i:
            str_i = str_i.replace('3', '')
            str_i = str_i.replace('5', '')
            str_i = str_i.replace('7', '')

            if str_i == '':
                result += 1

    print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
array = []
for i in range(n+1):
    if str(i).find("3") + str(i).find("5") + str(i).find("7") == len(str(i)):
        array.append(i)
print(len(array))

Submission status: Wrong Answer

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

N = int(input())

answer = 0

for i in range(1, N, 2):
	a_list = list(str(i))

	if '0' in a_list:
		pass
	elif '1' in a_list:
		pass
	elif '2' in a_list:
		pass
	elif '4' in a_list:
		pass
	elif '6' in a_list:
		pass
	elif '8' in a_list:
		pass
	elif '9' in a_list:
		pass
	else:
		if '3' in a_list:
			if '5' in a_list:
				if '7' in a_list:
					answer += 1

print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 0

def rec(pref):
	global cnt
	if pref <= n:
		cnt += 1
		for d in {3, 5, 7}:
			rec(pref * 10 + d)


rec(0)
print(cnt - 1)

Submission status: Wrong Answer

Solution code:
n = 10#int(input())
cnt = 0

def rec(pref):
	global cnt
	if pref <= n:
		cnt += 1
		for d in {3, 5, 7}:
			rec(pref * 10 + d)


rec(0)
print(cnt - 1)

Submission status: Wrong Answer

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

n = int(input())
nlen = len(str(n))
A = ['3','5','7']
lis = [0,0,6,36,150,540,1806,5796,18150]
ans = 0
for i in itertools.product(A, repeat=nlen):
    string = "".join(i)
    if('3' in string and '5' in string and '7' in string) :
        if(int(string) < n):
            ans += 1
for i in range(nlen-1):
    ans += lis[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

def main():
    n = int(input())
    c = 0
    for m in gen():
        if is_753(m):
            c += 1

        if m > n:
            break
    print(c)

def is_753(n):
    s = str(n)
    if '3' in s and '5' in s and '7' in s:
        return True
    else:
        return False

def gen():
    for i in itertools.count(1):
        for x in gen_1(i):
            yield x

def gen_1(num_digits):
    if num_digits == 1:
        yield 3
        yield 5
        yield 7
    else:
        for sub in gen_1(num_digits - 1):
            yield sub * 10 + 3
            yield sub * 10 + 5
            yield sub * 10 + 7

main()

Submission status: Wrong Answer

Solution code:
N = int(input().rstrip())
c = 0
for i in range(0,N):
    S = str(i)
    if "7" in S and "5" in S and "3" in S:
        if "0" not in S and "1" not in S and "2" not in S and "4" not in S and "6" not in S and "8" not in S and "9" not in S:
            c += 1
print(c)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

def check(i):
	s = str(i)
	for c in s:
		if c is '3' or c is '5' or c is '7':
			pass
		else:
			return False
	return True

t = 0
for i in range(1,N+1):
	if check(i):
		t+=1
print(t)

Submission status: Wrong Answer

Solution code:
N = int(input())
counter = 0
list = ['1','2','4','5','6','8','9']
for i in range(N+1):
    if '3' in str(i):
        if '5' in str(i):
            if '7' in str(i):
                for _ in list:
                    if _ not in str(i):
                        continue
                    else:
                        break
                counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n < 357:
    print(0)
else:
    print(len([i for i in range(357, n, 2) if set(str(i)) == {"3", "5", "7"}]))

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
N = int(input())

def count(pos, val, stat):
    ret = 0
    for i, num in enumerate([3, 5, 7]):
        if val + num * (10 ** pos) < N:
            stat_tmp = stat | (1 << i)
            if stat_tmp == 7: ret += count(pos + 1, val + num * (10 ** pos), stat_tmp) + 1
            else: ret += count(pos + 1, val + num * (10 ** pos), stat_tmp)
        else: break
    return ret

print(count(0, 0, 0))

Submission status: Wrong Answer

Solution code:
N = input()
counter = 0

for i in range(1, int(N)+1):
  a = list(str(i))
  if '7' in a and '5' in a and '3' in a and '1'not in a and '2' not in a and '4' not in a and '6' not in a and '8' not in a and '9' not in a:
    counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
def is_753(s) :
	if (s.find("0") > -1) :
		return False
	elif (s.find("1") > -1) :
		return False
	elif (s.find("2") > -1) :
		return False
	elif (s.find("4") > -1) :
		return False
	elif (s.find("6") > -1) :
		return False
	elif (s.find("8") > -1) :
		return False
	elif (s.find("9") > -1) :
		return False
	return True

N = int(input())
count = 0
# index = 0

for i in range(N+1) :
	s = str(i)
	if (is_753(s)) :
		count += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
m = 999
for i in range(len(S)-2):
    a = int(S[i:i+3])-753
    if abs(a)<m:
        m = abs(a)
print(m)

Submission status: Time Limit Exceeded

Solution code:
N = input()
n = len(N)
ans = 0
if n < 3:
    print(0)
    exit()
if n > 3:
    for i in range(3,n):
        ans += 3**i - 3*(2**i) + 3
a = int(N[0])
if a > 3:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
if a > 5:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
if a > 7:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
b = int(N[1])
if a == 3:
    if b > 3:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b > 5:
        ans += 3**(n-2) - (2**(n-2))
    if b > 7:
        ans += 3**(n-2) - (2**(n-2))
elif a == 5:
    if b > 3:
        ans += 3**(n-2) - (2**(n-2))
    if b > 5:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b > 7:
        ans += 3**(n-2) - (2**(n-2))
elif a == 7:
    if b > 3:
        ans += 3**(n-2) - (2**(n-2))
    if b > 5:
        ans += 3**(n-2) - (2**(n-2))
    if b > 7:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
if (a == 3 or a == 5 or a == 7) and (b == 3 or b == 5 or b == 7):
    c = (a*100 + b * 10 + 3) * 10**(n-3)
    d = int(N) + 1
    t = {"3","5","7"}
    for i in range(c,d):
        u = set(str(i))
        if u == t:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(len(str(N))):
    for j in range(3 * (10**i), 4 * (10**i)):
        if j > N:
            break
        if '0' not in str(j) and '1' not in str(j) and '2' not in str(j) and '4' not in str(j) and '6' not in str(
                j) and '8' not in str(j) and '9' not in str(j) and('7' in str(j) and '5' in str(j) and '3' in str(j)):
            count += 1
    for j in range(5 * (10**i), 6 * (10**i)):
        if j > N:
            break

        if '0' not in str(j) and '1' not in str(j) and '2' not in str(j) and '4' not in str(j) and '6' not in str(
                j) and '8' not in str(j) and '9' not in str(j) and('7' in str(j) and '5' in str(j) and '3' in str(j)):
            count += 1

    for j in range(7 * (10**i), 8 * (10**i)):
        if j > N:
            break
        if '0' not in str(j) and '1' not in str(j) and '2' not in str(j) and '4' not in str(j) and '6' not in str(
                j) and '8' not in str(j) and '9' not in str(j) and('7' in str(j) and '5' in str(j) and '3' in str(j)):
            count += 1
    else:
        continue
    break

print(count)

Submission status: Time Limit Exceeded

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

for i in range(len(str(N))):
    for j in range(3 * (10**i), 8 * (10**i)):
        if j > N:
            break
        if '0' not in str(j) and '1' not in str(j) and '2' not in str(j) and '4' not in str(j) and '6' not in str(j) and '8' not in str(j) and '9' not in str(j) and('7' in str(j) and '5' in str(j) and '3' in str(j)):
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
n = len(str(N)) - 1
ans = 0
for i in range(3, n+1):
  ans += 3**i - (2**i)*3 + 3

t = 3**n - 2**(n+1) + 1

if int(str(N)[0]) == 3:
  for i in range(3*(10**n), N+1):
    s = set([j for j in str(i)])
    if ('5' in s) and ('7' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) == 4:
  ans += t
elif int(str(N)[0]) == 5:
  ans += 3**n - (2**n)*3 + 3 + 2**n - 2
  for i in range(5*(10**n), N+1):
    s = set([j for j in str(i)])
    if ('3' in s) and ('7' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) == 6:
  ans += 2*t
elif int(str(N)[0]) == 7:
  ans += 2*t
  for i in range(7*(10**n), N+1):
    s = set([j for j in str(i)])
    if ('3' in s) and ('5' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) > 7:
  ans += 3*t
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
n = len(str(N)) - 1
ans = 0
for i in range(3, n+1):
  ans += 3**i - (2**i)*3 + 3

t = 3**n - 2**(n+1) + 1

if int(str(N)[0]) == 3:
  for i in range(3*(10**n), N+1):
    s = set([j for j in str(i)])
    if ('5' in s) and ('7' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) == 4:
  ans += t
elif int(str(N)[0]) == 5:
  ans += 3**n - (2**n)*3 + 3 + 2**n - 2
  for i in range(5*(10**n), N+1):
    s = set([j for j in str(i)])
    if ('3' in s) and ('7' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) == 6:
  ans += 2*t
elif int(str(N)[0]) == 7:
  ans += 2*t
  for i in range(7*(10**n), min(N+1, 8*(10**n))):
    s = set([j for j in str(i)])
    if ('3' in s) and ('5' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) > 7:
  ans += 3*t
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
n = len(str(N)) - 1
ans = 0
for i in range(3, n+1):
  ans += 3**i - (2**i)*3 + 3

t = 3**n - 2**(n+1) + 1

if int(str(N)[0]) == 3:
  for i in range(3*(10**n), N+1):
    s = set([j for j in str(i)])
    if ('5' in s) and ('7' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) == 4:
  ans += t
elif int(str(N)[0]) == 5:
  ans += 3**n - (2**n)*3 + 3 + 2**n - 2
  for i in range(5*(10**n), N+1):
    s = set([j for j in str(i)])
    if ('3' in s) and ('7' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) == 6:
  ans += 2*t
elif int(str(N)[0]) == 7:
  ans += 2*t
  for i in range(7*(10**n), min(N+1, 8*(10**n))):
    s = set([j for j in str(i)])
    if ('3' in s) and ('5' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) > 7:
  ans += 3*t
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from bisect import bisect_right

num_lst = {}
for i in range(7):
    for lst in itertools.combinations_with_replacement(["3", "5", "7"], i):
        n_lst = list(lst) + ["3", "5", "7"]
        for ll in itertools.permutations(n_lst):
            num_lst[int("".join(ll))] = 1
num_sort = []
for num, _ in num_lst.items():
    num_sort.append(num)
num_sort.sort()

n = int(input())
print(bisect_right(num_sort, n))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())
stack, seen = deque(["0"]), deque([])
c = 0
while stack:
  x = stack.pop()
  seen.append(x)
  if int(x)>N:
    continue
  if all(x.count(i)>0 for i in "753"):
    c += 1
  for i in "753":
    if x+i in seen:
      continue
    else:
      stack.append(x+i)
print(c)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans=0
a=['3','5','7','0']
cnt=[]
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):
                                    for i9 in range(4):
                                        for i10 in range(3):
                                            cnt.append(a[i1])
                                            cnt.append(a[i2])
                                            cnt.append(a[i3])
                                            cnt.append(a[i4])
                                            cnt.append(a[i5])
                                            cnt.append(a[i6])
                                            cnt.append(a[i7])
                                            cnt.append(a[i8])
                                            cnt.append(a[i9])
                                            if int(a[i1]+a[i2]+a[i3]+a[i4]+a[i5]+a[i6]+a[i7]+a[i8]+a[i9]+a[i10])<=n and cnt.count('0')<2:
                                                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

l753 = ['3', '5', '7']
ans = 0

for i in range(n+1):
    l = list(str(i))
    if all((j in l753) for j in l) and len(set(l)) == 3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

cnt = 0
target = set(["3","5","7"])
for i in range(1,n+1):
  check = set(str(i))
  if (len(target.intersection(check))==3) & (len(check)==3):
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools 
n=int(input())
if(n<=333):
  print(0)
  exit()

ans=0
for ket in range(3,100):
  for xxx in  itertools.product([3,5,7],repeat=ket):
    tmp=list(xxx)[::1]
    hoge=0
    for j in range(len(tmp)):
      hoge=hoge*10+tmp[j]
    if(str(hoge).count("3")==0 or str(hoge).count("5")==0 or str(hoge).count("7")==0):
      ans-=1
    ans+=1
    if(hoge==n):
      print(ans)
      exit()

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop, heapify
from itertools import product

N = int(input())

hq = []

# initial setting
for c in product([3, 5, 7], repeat=3):
    heappush(hq, c[0]*100 + c[1]*10 + c[2])

ans = []
while (hq):
    now = heappop(hq)
    if now <= N:
        if (len(set(str(now))) == 3):
            ans.append(now)
        digit = pow(10, len(str(now)))
        for i in (3, 5, 7):
            heappush(hq, now*10 + i)
            heappush(hq, now + i*digit)

print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop, heapify
from itertools import product

N = int(input())

hq = []

# initial setting
for c in product([3, 5, 7], repeat=3):
    heappush(hq, c[0]*100 + c[1]*10 + c[2])

ans = 0
while (hq):
    now = heappop(hq)
    if now <= N and (len(set(str(now))) == 3):
        ans += 1
    digit = pow(10, len(str(now)))
    if now*10 <= N:
        for i in (3, 5, 7):
            heappush(hq, now*10 + i)
    if now+3*digit <= N:
        for i in (3, 5, 7):
            heappush(hq, now + i*digit)
    hq = list(set(hq))
    heapify(hq)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

sitigosan = ['7', '5', '3']
non_sitigosan = ['0', '1', '2', '4', '6', '8', '9']

cnt = 0
for i in range(1, N+1):
    str_i = str(i)
    flag = True
    for n in sitigosan:
        if n not in str_i:
            flag = False
            break
    if flag :
        for m in non_sitigosan:
            if m in str_i:
                flag = False
                break
    if flag :
        cnt += 1        
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a={"3","5","7"}
ans=0
for v in range(n+1):
    k=set(str(v))
    if k ==a:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a={"3","5","7"}
ans=0
for v in range(n+1):
    k=set(list(str(v)))
    if k ==a:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import statistics
# import numpy as np
# n = int(input())
# a, b, c, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
n = int(input())
# n, m = list(map(int, input().split()))
# n, m = list(map(int, input().split()))
# x = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
# n = int(input())
# n, m = list(map(int, input().split()))
if n < 357:
    print(0)
else:
    l = len(str(n))
    num = [3, 5, 7]*l
    data = []
    for j in range(3, l+1):
        for v in itertools.permutations(num, j):
            a = ""
            for i in range(j):
                a += str(v[i])

            if int(a) <= n:
                if "3" in a and "5" in a and "7" in a:
                    data.append(a)
            # print(v)
    # print(data)
    ans = set(list(data))
    print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
def abc114_c():
  n = int(input())

  def bit_mask(n):
    b, d = 4, 9  # bit, digit
    arr = []
    for i in range(d-1, -1, -1):
      arr.append(n // (b**i))
      n = n % (b**i)
    ret = str(int(''.join(map(str, arr))))
    return ret

  def decode753(arr):
    ret = ''.join(map(str, arr)).replace('3','7').replace('2','5').replace('1','3')
    return int(ret)

  ans = 0
  b, d = 4, 9
  for m in range(b**d):
    mask = bit_mask(m)
    if mask.count('0') == 0 and mask.count('1') > 0 and mask.count('2') > 0 and mask.count('3') > 0:
      x = decode753(mask)
      if x <= n: ans += 1
      else: break
  print(ans)

abc114_c()

Submission status: Time Limit Exceeded

Solution code:
def nyu():
    N = int(input())

    return N

def kansu(N):

    cnt = 0
    n = 100


    while n <= N:
    #    print("n",n)
        flg = False
        str_n = str(n)
        for s_n in range(len(str_n)-1):
            if str_n[s_n]  == "1" or str_n[s_n]  == "2" or str_n[s_n]  == "4" or str_n[s_n]  == "6" or str_n[s_n]  == "8" or str_n[s_n]  == "9" :
                n += 10**(len(str_n)-(s_n+1))
                flg = True
                break
        if flg == True:
            continue

            
        # n_first = int(str_n[0])
        # n_second = int(str_n[1])
        # n_third = int(str_n[2])
        # if n_first  == 1 or n_first  == 2 or n_first  == 4 or n_first  == 6 or n_first  == 8 or n_first  == 9 :
        #    n += 10**(len(str_n)-1)
        #    continue

        # if n_second  == 1 or n_second  == 2 or n_second  == 4 or n_second  == 6 or n_second  == 8 or n_second  == 9 :
        #    n += 10**(len(str_n)-2)
        #    continue

        # if n_third  == 1 or n_third  == 2 or n_third  == 4 or n_third  == 6 or n_third  == 8 or n_third == 9 :
        #    n += 10**(len(str_n)-3)
        #    continue

        if  "7" in str_n and "5" in str_n and "3" in str_n and "0" not in str_n and "1" not in str_n and "2" not in str_n and "4" not in str_n and "6" not in str_n and "8" not in str_n and "9" not in str_n:
            cnt += 1
        #    print("str_n",str_n)
        n = n+1
    print(cnt)





N = nyu()
kansu(N)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
cnt=0
 
for i in range(1, N+1):
    i=str(i)
    if "1" in i or "2" in i or "4" in i or "6" in i or "8" in i or "9" in i or "0" in i:
        continue
    elif "3" in i and "5" in i and "7" in i:
        cnt+=1
 
print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(1, N+1):
    i=str(i)
    if "1" in i or "2" in i or "4" in i or "6" in i or "8" in i or "9" in i or "0" in i:
        continue
    elif "3" in i and "5" in i and "7" in i:
        cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import copy
from collections import deque

n = int(input())

ans = 0
array = ['7','5','3']

count = 0
d = deque()
d.append(([],set()))

while len(d) != 0:
  s,used = d.pop()
  if len(s) != 0 and int(''.join(s)) > n:
    continue
  
  if len(used) == 3:
    count += 1
    
  for c in array:
    cp_s = copy.deepcopy(s)
    cp_used = copy.deepcopy(used)
    cp_s.append(c)
    cp_used.add(c)
    d.append((cp_s,cp_used))
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
from collections import deque

n = int(input())

ans = 0
array = ['7','5','3']

count = 0
d = deque()
d.append(([],set()))

while len(d) != 0:
  s,used = d.pop()
  if len(s) != 0 and int(''.join(s)) > n:
    continue
  
  if len(used) == 3:
    count += 1
    
  for c in array:
    cp_s = copy.deepcopy(s)
    cp_used = copy.deepcopy(used)
    cp_s.append(c)
    cp_used.add(c)
    d.append((cp_s,cp_used))
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy

def saiki(s,used,n):
  if int(s) > n:
    return 0

  count = 0
  arr = ['7','5','3']
  if len(used) == 3:
    count += 1
  
  for c in arr:
    cp_used = copy.deepcopy(used)
    cp_used.add(c)
    count += saiki(s+c,cp_used,n)
    
  return count
  

n = int(input())

ans = 0
array = []

used = set()
ans = saiki('7',set('7'),n) + saiki('5',set('5'),n) + saiki('3',set('3'),n)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

cnt=0
for n in range(1,N+1):
  item_cnt=0
  num_digit =len(str(n))
  chk_n = n
  chk_7 = 0
  chk_5 = 0
  chk_3 = 0
  for i in range(num_digit):
    a = chk_n % 10
    chk_n = chk_n // 10
    if a == 7:
      chk_7 += 1
      item_cnt += 1
      if item_cnt == num_digit and chk_7 > 0 and chk_5 > 0 and chk_3 >0:
        cnt +=1
        #print(n)
        break
    elif a== 5:
      chk_5 += 1
      item_cnt += 1
      if item_cnt == num_digit and chk_7 > 0 and chk_5 > 0 and chk_3 >0:
        cnt +=1
        #print(n)
        break
    elif a == 3:
      chk_3 += 1
      item_cnt += 1
      if item_cnt == num_digit and chk_7 > 0 and chk_5 > 0 and chk_3 >0:
        cnt +=1
        #print(n)
        break      
   
    else:
      break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
c = 0
for i in range(357, N + 1, 2):
  hoka = False
  aru = [False] * 3
  for s in str(i):
    if s == '3':
      aru[0] = True
    elif s == '5':
      aru[1] = True
    elif s == '7':      
      aru[2] = True
    else:
      hoka = True
      break
  if hoka == False:
    if aru.count(False) == 0:
      c += 1
          
print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
num = 4**9
ans = 0
for i in range(num):
    a = 0
    b = 0
    c = 0
    d = 0
    s = i
    for j in range(9):
        a += 0 * int(s % 4 == 0) * 10 ** j
        b += 3 * int(s % 4 == 1) * 10 ** j
        c += 5 * int(s % 4 == 2) * 10 ** j
        d += 7 * int(s % 4 == 3) * 10 ** j
        s = s // 4
    tmp = a + b + c + d
    if tmp > n:
        break
    tmp = str(tmp)
    if b > 0 and c > 0 and d > 0 and tmp.count('0') == 0:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
count = 0
for i in range(1,n+1):
    s = list(str(i))
    se = sorted(list(set(s)))
    #print(se)
    if se == ['3','5','7']:
        #print(i)
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
cnt=0
for i in range(1,N+1):
    s=str(i)
    if "3" in s and "5" in s and "7" in s:
        if len(set(s))==3:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
cnt=0
for i in range(n+1):
  if set(str(i))=={'7','5','3'}:
    cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

cnt = 0
for i in range(1,N+1,2):
    tmp = set(str(i))
    if len(tmp)==3 and '7' in tmp and '5' in tmp and '3' in tmp:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A =[]

for i in range(1,N+1):
    if i > 9:
        T = list(str(i))
        A.append(T)
    else:
        A.append([str(i)])

cnt = 0
for i in A:
    cnt_not = 0

    for j in i:
        if j == '1' or j == '2' or j == '4' or j == '6' or j == '8' or j == '9' or j == '0' :
            cnt_not += 1
    if cnt_not == 0:
        B = set(i)
        if len(B) == 3:
            cnt +=1
print(cnt)