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: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
count = 0

for i in range(1, n + 1, 2):
	c = collections.Counter(list(str(i)))
	if len(c.keys()) == 3:
		if (c['3'] != 0) and (c['5'] != 0) and (c['7'] != 0):
			count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
count = 0

for i in range(1, n + 1):
	c = collections.Counter(list(str(i)))
	if len(c.keys()) == 3:
		if (c['3'] != 0) and (c['5'] != 0) and (c['7'] != 0):
			count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
print(len([n for n in range(1,N+1,2) if set(str(n))=={'3','5','7'}]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

result = len(
    [str(x) for x in range(1, n+1)
     if '7' in str(x) and '5' in str(x) and '3' in str(x) and '0' not in str(x) and '1' not in str(x) and '2' not in str(x) and '4' not in str(x) and '6' not in str(x) and '8' not in str(x) and '9' not in str(x)]
)
print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
count=0
for i in range(N):
    I=i+1
    Istr = str(I)
    if Istr.count("3")>0 and Istr.count("5")>0 and Istr.count("7"):
        if Istr.count("0") == 0 and Istr.count("1") == 0 and Istr.count("2") == 0 and Istr.count("4")==0 and Istr.count("6")==0 and Istr.count("8")==0 and Istr.count("9")==0:
            count+=1
        else:
            pass
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力

n = int(input())

cnt = 0
pre = ['753', '735', '573', '537', '375', '357']

for i in range(n):

    l = [s for s in str(i+1)]
    
    #print(set(l))
    uni = ''.join(set(l))
    
    for p in pre:
        if uni == p : 
            cnt+=1
            #print(uni)
            break
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def make_753(s,number,n,array):
    if n < int(s) : return array
    elif len(str(n)) == len(s)-1 :
        if int(s) not in array:
            array.append(int(s))
            return array
    else:
        s+=number
        make_753(s,"3",n,array)
        make_753(s,"5",n,array)
        make_753(s,"7",n,array)
    return array
    
N = int(input())
array = []
array_sort=[]
array_753 = []
score = 0
if N >= 1000:
    for i in range(3,len(str(N))):
        score += 3**i - 2**i*3 +3
array = (make_753("0","3",N,array) + make_753("0","5",N,array) + make_753("0","7",N,array))
for i in array:
    if i not in array_sort: array_sort.append(i)
for i in array_sort:
    if i <= N and i not in array_753:
        if "3" in str(i) and "5" in str(i) and "7" in str(i):
            array_753.append(i)
            score += 1
print(score)

Submission status: Time Limit Exceeded

Solution code:
#階乗を計算する関数
def kaijo(n):
    result = 1
    for i in range(1,n+1):
        result *= i
    return result
#N桁の七五三数の数
def sum_753(N):
    goukei = 0
    for i in range(1, len(str(N))-1):
        for j in range(1, len(str(N))-i):
            k = len(str(N)) - i - j

            goukei += kaijo(len(str(N)))//(kaijo(i)*kaijo(j)*kaijo(k))
    
    return goukei

N = int(input())
count=0
if N < 357 : print(0) #一個もない場合
elif N >= 357 and N < 375:print(1)
elif N >= 375 and N < 537:print(2)
elif N >= 537 and N < 573:print(3)
elif N >= 573 and N < 735:print(4)
elif N >= 735 and N < 753:print(5)
elif N >= 753 and N <= 999:print(6)
else:
    for i in range(3,len(str(N))):
        count += sum_753(10**(i-1))
    for i in range(10**(i), N+1):
        if "3" in str(i) and "5" in str(i) and "7" in str(i):
            if "0" not in str(i) and "1" not in str(i) and "2" not in str(i) and "4" not in str(i) and "6" not in str(i) and "8" not in str(i) and "9" not in str(i):
                count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
print(sum([1 if str(i).count('3') > 0 and str(i).count('5') > 0 and str(i).count('7') > 0 and len(str(i)) == str(i).count('3') + str(i).count('5') + str(i).count('7') else 0 for i in range(1,n+1)]))

Submission status: Time Limit Exceeded

Solution code:
import re

N = int(input())

ans = 0
for i in range(1, N+1):
    n = i
    flags = 0
    while True:
        flags |= 1 << (n % 10)
        n //= 10
        if n == 0:
            break
    if flags == 0xA8:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
counter = 0
for i in range(357, N + 1):
    string = str(i)
    count3 = string.count("3")
    count5 = string.count("5")
    count7 = string.count("7")
    #print(i, count3, count5, count7)
    if count3 + count5 + count7 == len(string) and 0 not in [count3, count5, count7]:
        counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
K = 0
A = []
count = 0
while N != 0:
	if ((N%10)-1)//2 >= 3:
		A.append(3)
		N = N//10
	elif ((N%10)-1)//2 >= 2:
		A.append(2)
		N = N//10
	elif ((N%10)-1)//2 >= 1:
		A.append(1)
		N = N//10
	else:
		A.append(3)
		N = N//10 - 1

exponent = 0
for a in A:
	K += a * (4**exponent)
	exponent +=1

B = A
C = A
while len(B) == len(C):
	B = C
	if (1 in C) and (2 in C) and (3 in C) and not (0 in C):
		count += 1
	K -= 1
	l  = K
	C = []
	while l != 0:
		C.append(l%4)
		l = l//4
        
m = len(C)

for j in range(3, m+1 ):
	count += 3**j - 3*(2**j-1)

print(count)

Submission status: Time Limit Exceeded

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

while N != 0:
	if max(0, ((N%10)-1)//2) >= 3:
		A.append(3)
		N = N//10
	elif max(0, ((N%10)-1)//2) >= 2:
		A.append(2)
		N = N//10
	elif max(0, ((N%10)-1)//2) >= 1:
		A.append(1)
		N = N//10
	else:
		A.append(3)
		N = N//10 - 1

#print(A)

exponent = 0
for a in A:
	M += a * (4**exponent)
	exponent +=1

#print(M)

K = M
for x in range(M):
	if (1 in A) and (2 in A) and (3 in A) and not (0 in A):
		count += 1
	K -= 1
#	print("K = " + str(K))
	A  = []
	while K != 0:
		A.append(K%4)
		K = K//4
#	print("count = " + str(count))
#	print("A = " + str(A) )
	
	exponent = 0
	for a in A:
		K += a * (4**exponent)
		exponent +=1


print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a={7,5,3}
cnt=0

digit = lambda t:(digit(t//10) + [t%10]) if t > 0 else []

for i in range(1, n+1):
	l = set(digit(i))
	if (a&l == a) and not(a^l):
		cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=input()

count=0
for j in range(1,int(n)+1):
    X=[]
    X=[int(x) for x in list(str(j))]
    if set(X)=={3,5,7}:
        count+=1
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=input()

count=0
for j in range(1,int(n)+1):
    X=[]
    str_j=str(j)
    for k in range(len(str_j)):
        X.append(int(str_j[k]))
    if set(X)=={3,5,7}:
        count+=1
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
b=int(input())
th=fi=se=count=0
for i in range(355,b+1):
    m=str(i)
    l=len(m)
    for x in range(l):
        if int(m[x])%2==1:
            if 3==int(m[x]) :th=th+1
            if 5==int(m[x]) :fi=fi+1
            if 7==int(m[x]) :se=se+1
    if l==(th+fi+se) and th!=0 and fi!=0 and se!=0:count=count+1
    th=fi=se=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
b=int(input())
th=fi=se=count=0
for i in range(355,b+1,1):
    m=str(i)
    l=len(m)
    for x in range(l):
        if 3==int(m[x]) :
            th=th+1
        if 5==int(m[x]) :
            fi=fi+1
        if 7==int(m[x]) :
            se=se+1
    if l==(th+fi+se) and th!=0 and fi!=0 and se!=0:
        count=count+1
    th=fi=se=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy

ssst=str(input())
b = int(copy.copy(ssst))
th=fi=se=count=0

for i in range(355,b+1):
    m=str(i)
    if i%2==1:
        for x in range(len(m)):
            if 3==int(m[x]) :
                th=th+1
            if 5==int(m[x]) :
                fi=fi+1
            if 7==int(m[x]) :
                se=se+1
        if len(m)==(th+fi+se) and th!=0 and fi!=0 and se!=0:
            count=count+1
        th=fi=se=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy

ssst=str(input())
b = int(copy.copy(ssst))
count=0
th=fi=se=0

for i in range(355,b+1):
    m=str(i)
    for x in range(len(m)):
        if 3==int(m[x]) :
            th=th+1
        if 5==int(m[x]) :
            fi=fi+1
        if 7==int(m[x]) :
            se=se+1
    if len(m)==(th+fi+se) and th!=0 and fi!=0 and se!=0:
        count=count+1
    th=fi=se=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy

ssst=str(input())
b = int(copy.copy(ssst))

th=fi=se=count=0

for i in range(100,b+1):
    m=str(i)
    if i%2==1:
        for x in range(len(m)):

            for j in range(10):
                if j==int(m[x]) and j==3:
                    th=th+1
                if j==int(m[x]) and j==5:
                    fi=fi+1
                if j==int(m[x]) and j==7:
                    se=se+1
        if len(m)==(th+fi+se) and th!=0 and fi!=0 and se!=0:
            count=count+1
            #print(count,"  ",i ," ",x)
        th=fi=se=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy

#n=int(input())
#s=str(n)
ssst=str(input())
b = int(copy.copy(ssst))
#lit = list(map(int,input().split()))
count=0
#mmm=int(max(lit))*n
#ans=mmm-int(sum(lit))
#print(ans)
#arr=[]
#arr=s.rsplit("3","5","7")

th=0
fi=0
se=0

for i in range(100,b+1):
    #print(i,"i")
    m=str(i)
    for x in range(len(m)):

        for j in range(10):
            if j==int(m[x]) and j==3:
                th=th+1
            if j==int(m[x]) and j==5:
                fi=fi+1
            if j==int(m[x]) and j==7:
                se=se+1
    if len(m)==(th+fi+se) and th!=0 and fi!=0 and se!=0:
        count=count+1
        #print(count,"  ",i ," ",x)
    th=0
    fi=0
    se=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = input()
counter = 0
for i in range(1, int(n) + 1):
    li = list(str(i))
    a = li.count("3")
    b = li.count("5")
    c = li.count("7")
    if a > 0 and b > 0 and c > 0 and a+b+c==len(li):
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
for i in range(n+1):
    num = list(str(i))
    if "7" in num and "5" in num and "3" in num:
        if len("".join(num).replace("7","").replace("5","").replace("3",""))==0:
            ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def check_753(N):
    num = [0 for _ in range(10)]
    for i in range(len(N)):
        num[int(N[i])] = 1
    if sum(num) == 3:
        if num[3]+num[5]+num[7] == 3:
            return True
        else:
            return False
    else:
        return False

count = 0
for i in range(N):
    count += int(check_753(str(i+1)))
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=0
for i in range(1,n+1):
    s=[]
    if "3" in str(i) and "5" in str(i) and "7" in str(i):
        for j in str(i):
            s.append(j)
        if len(set(s)) == 3:
                a+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
cc=0
answer=0

while cc<=n:
  #length=len(str(cc))
  n3=str(cc).count("3")
  n5=str(cc).count("5")
  n7=str(cc).count("7")
  
  if len(str(cc))==n3+n5+n7 and min(n3,n5,n7)!=0:
    #print(cc,n3,n5,n7,answer)
    answer=answer+1
    
  cc=cc+1
  
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

count = 0

for i in range(1,N+1):
  if set(str(i)) == {"7", "5", "3"}:
    count += 1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from functools import lru_cache

@lru_cache(maxsize=1000)
def f(k, t='357'):
    tmp = [int(i) for i in t]
    res = []
    if k ==len(tmp):
        return list((set([i for i in itertools.permutations(tmp, k)])))
    else:
        a1 = ""
        for i in sorted(t+'3'):
            a1+=i
        a2 = ""
        for i in sorted(t+'5'):
            a2+=i
        a3 = ""
        for i in sorted(t+'7'):
            a3+=i
        return list(set(f(k, a1) + f(k, a2) + f(k, a3)))

def f2(res, N):
    cnt = 0
    n  = int(N)
    for tmp in res:
        s = ''
        for i in tmp:
            s += str(i)
        if int(s) <= n:
            cnt += 1
    return cnt
def f3(N):
    keta = len(N)
    result = 0
    for i in range(3, keta+1):
        res = f(i)
        result += f2(res, N)
    return result
if __name__ == '__main__':
    print(f3(input()))

Submission status: Time Limit Exceeded

Solution code:
import itertools
def f(k, tmp = [3, 5, 7]):
    res = []
    if k <=len(tmp):
        return list((set([i for i in itertools.permutations(tmp, k)])))
    else:
        return list(set(f(k, tmp+[3]) + f(k, tmp+[5]) + f(k, tmp+[7])))
def f2(res, N):
    cnt = 0
    n  = int(N)
    for tmp in res:
        s = ''
        for i in tmp:
            s += str(i)
        if int(s) <= n:
            cnt += 1
    return cnt
def f3(N):
    keta = len(N)
    result = 0
    for i in range(3, keta+1):
        res = f(i)
        result += f2(res, N)
    return result
if __name__ == '__main__':
    print(f3("99999999"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
#S = 3600
count = 0

for i in range(S):
    ss = [int(x) for x in list(str(i+1))]
    
    if list(set(ss)) == [3,5,7]:
        count = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
B = ['3', '5', '7']
count=0
ans=0
for i in range(357, min(n+1, 777777753), 2):
    A = list(str(i))
    C = list(set(A))
    C.sort()
    if(C==B):
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def is753Value(x:int):
    x = str(x)
    if '1' in x or '2' in x or '4' in x or '6' in x or '8' in x or '9' in x or '0' in x :
        return False
    elif '7' in x and '5' in x and '3' in x:
        return True
    return False

N = int(input())
counter = 0
for x in range(1, N+1, 2):
    if is753Value(x):
        counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
count = 0
for n in range(N+1):
    flag = 0
    count3 = 0
    count5 = 0
    count7 = 0
    tmp = list(str(n))
    for i in range(len(tmp)):
        if tmp[i] != '3':
            if tmp[i] != '5':
                if tmp[i] != '7':
                    flag = 1
                    break
        if tmp[i] == '3':
            count3 +=1
        elif tmp[i] == '5':
            count5 += 1
        else:
            count7 += 1
    if flag != 1:
        if (count3 >= 1) & (count5 >= 1) & (count7 >= 1):
            count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jan  2 21:43:48 2019

@author: Yamazaki Kenichi
"""

N = int(input())

ans = 0
for i in range(N+1):
    b=0
    if str(i).count('3')>=1:
        b = len(str(i))-str(i).count('3')
        if str(i).count('5')>=1:
            b -= str(i).count('5')
            if str(i).count('7')>=1:
                b -= str(i).count('7')
                if b == 0:
                    ans += 1
#                    print(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C - 755 解2
Set753 = {7, 5, 3}

num = int(input())
count = 0
for i in range(357, num+1):
    nSet = set([])
    n = i
    while n>0:
        d = n%10
        if d in Set753:
            nSet.add(d)
            n //= 10
        else: 
            nSet = set([])
            break
    if nSet=={}: continue 
    elif nSet==Set753: 
        #print(i,end=', ') #
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
Num753 = {7, 5, 3}

def getDigitList(n):
    list = []
    while n>0:
        list.append(n%10)
        n //= 10
    list.reverse()
    if list==[]: list = [0]
    return list

def getDigitSet(n):
    nSet = set([])
    while n>0:
        nSet.add(n%10)
        n //= 10
    if nSet=={}: nSet = {0}
    return nSet

S = input()
num = int(S)
count = 0
for i in range(357, num+1):
    nSet = getDigitSet(i)
#    if len(nSet)!=3: continue
#    is753 = True
#    for d in nSet:
#        if not (d in Num753):
#            is753 = False 
#            break
    if nSet==Num753: 
        #print(i,end=', ') #
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
C - 755

"""
def gen_357():
    def conv(n):
        res = []
        while n:
            n, r = divmod(n, 4)
            res.append(str(str(r)))
        if not res:
            res = ['0']
        return ''.join(res[::-1]).translate(str.maketrans('0123', '0357'))

    n = 0
    while True:
        t = conv(n)
        while '0' in t or len(set(list(t))) != 3:
            n += 1
            t = conv(n)
        yield t
        n += 1


def solve(n):
    ans = 0
    g = gen_357()
    while True:
        t = next(g)
        if int(t) > n:
            break
        ans += 1
    return ans


n = int(input())
ans = solve(n)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
C - 755

"""
import sys


from itertools import product

def gen_357():
    def conv(n):
        res = []
        while n:
            n, r = divmod(n, 4)
            res.append(r)
        t = list(map(str, res[::-1]))
        if not t: t = ['0']
        x = ''.join(t).translate(str.maketrans('0123', '0357'))
        return int(x)

    n = 0
    while True:
        t = conv(n)
        while '0' in str(t) or len(set(list(str(t)))) != 3:
            n += 1
            t = conv(n)
        yield t
        n += 1


def solve(n):
    ans = 0
    g = gen_357()
    while True:
        t = next(g)
        if t > n:
            break
        ans += 1
    return ans


def main(args):
    n = int(input())
    ans = solve(n)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
def judge(n):
  n = str(n)
  if '7' in n:
    if '5' in n:
      if '3' in n:
        if '1' not in n:
          if '2' not in n:
            if '4' not in n:
              if '6' not in n:
                if '8' not in n:
                  if '9' not in n:
                    if '0' not in n:
                      return True
  return False



n = int(input())
cnt = 0
for i in range(1, n+1):
  if judge(i):
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0
for i in range(n):
    st = str(i+1)
    if ("7" in st) and ("5" in st) and ("3" in st) \
       and not("1" in st) and not("2" in st) and not("4" in st) \
       and not("6" in st) and not("8" in st) and not("9" in st) and not("0" in st):
        cnt = cnt + 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

ans=0
for i in range(N+1):
    c=len(str(i))
    c3=str(i).count("3")
    c5=str(i).count("5")
    c7=str(i).count("7")
    if (c3>0) & (c5>0) & (c7>0) & (c==c3+c5+c7):
        ans+=1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = input(" ")

ans=0
for I in range(int(x)+1):
    a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    i = str(I)
    for l in range(len(i)):
        if i[l] == "0":
            a[0] += 1
        if i[l] == "1":
            a[1] += 1
        if i[l] == "2":
            a[2] += 1
        if i[l] == "3":
            a[3] += 1
        if i[l] == "4":
            a[4] += 1
        if i[l] == "5":
            a[5] += 1
        if i[l] == "6":
            a[6] += 1
        if i[l] == "7":
            a[7] += 1
        if i[l] == "8":
            a[8] += 1
        if i[l] == "9":
            a[9] += 1

    if a[0]==0:
        if a[1]==0:
            if a[2]==0:
                if a[3]!=0:
                    if a[4]==0:
                        if a[5]!=0:
                            if a[6]==0:
                                if a[7]!=0:
                                    if a[8]==0:
                                        if a[9]==0:
                                            ans+=1

print (ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

count = 0

for i in range(x+1):
    y = str(i)

    hako = []
    for k in range(10):
        hako.append(0)

    for j in range(len(y)):
        if y[j] == '0':
            hako[0] += 1
        if y[j] == '1':
            hako[1] += 1
        if y[j] == '2':
            hako[2] += 1
        if y[j] == '3':
            hako[3] += 1
        if y[j] == '4':
            hako[4] += 1
        if y[j] == '5':
            hako[5] += 1
        if y[j] == '6':
            hako[6] += 1
        if y[j] == '7':
            hako[7] += 1
        if y[j] == '8':
            hako[8] += 1
        if y[j] == '9':
            hako[9] += 1

    if hako[0] >= 1 or hako[1] >= 1 or hako[2] >= 1 or hako[4] >= 1 or hako[6] >= 1 or hako[8] >= 1 or hako[9] >= 1:
        continue

    if hako[3] >= 1 and hako[5] >= 1 and hako[7] >= 1:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a753=['357','375','537','573','735','753']
b753=['3','5','7','35','37','53','57','73','75'] + a753

count=0
p=-1

b='0'
while True:
    for a in a753:
        c = int(b+a)
        if c<=N:
            count+=1
        else:
            break
    if c>N:
        break
    p+=1
    if p>=len(b753):
        p=0


print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

count = 0
for i in range(1, N+1):
	if set(str(i)) != {"3", "5", "7"}:
		continue
	count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)

d={}

def c(s):
	a = [0] * 10
	for i in s:
		a[int(i)] += 1
	if a[3] != 0 and a[5] != 0 and a[7] != 0:
		return True
	else:
		return False

def r(m, s):
	global d
	if s == "":
		pass
	elif m < int(s) or (s in d):
		return 0
	ret = 0
	if c(s):
		ret += 1
		d[s] = 1
	ret += r(m,s+"3")
	ret += r(m,s+"5")
	ret += r(m,s+"7")
	ret += r(m,"3"+s)
	ret += r(m,"5"+s)
	ret += r(m,"7"+s)
	return ret

def main():
	n = int(input())
	print(r(n,""))
	return
main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nn = 0
i = 357

while i <= n:
  s = str(i)
  if '3' in s:
    if '5' in s:
      if '7' in s:
        if ('0' in s or '1' in s or '2' in s or '4' in s or '6' in s or '8' in s or '9' in s) is False:
          #print(i)
          nn += 1
  if i % 10 == 7:
    i += 6
  else:
    i +=2
print(nn)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nn = 0
i = 357

while i <= n:
  s = str(i)
  if ('0' in s or '1' in s or '2' in s or '4' in s or '6' in s or '8' in s or '9' in s) is False:
    if '3' in s:
      if '5' in s:
        if '7' in s:
          #print(i)
          nn += 1
  if i % 10 == 7:
    i += 6
  else:
    i +=2
print(nn)

Submission status: Time Limit Exceeded

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

if n >= 357:
    for i in range(357,n+1):
        s = str(i)
        if ('0' in s or '1' in s or '2' in s or '4' in s or '6' in s or '8' in s or '9' in s) is False:
            if '3' in s:
              if '5' in s:
                if '7' in s:
                  #print(i)
                  nn += 1
print(nn)

Submission status: Time Limit Exceeded

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

if n >= 357:
    for i in range(357,n+1):
        s = str(i)
        if ('0' in s or '1' in s or '2' in s or '4' in s or '6' in s or '8' in s or '9' in s) is False:
            if '3' in s and '5' in s and '7' in s:
                #print(i)
                nn += 1
print(nn)

Submission status: Time Limit Exceeded

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

if n >= 357:
    for i in range(357,n+1):
        s = str(i)
        if '3' in s and '5' in s and '7' in s:
            if ('0' in s or '1' in s or '2' in s or '4' in s or '6' in s or '8' in s or '9' in s) is False:
                #print(i)
                nn += 1
print(nn)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  2 20:06:49 2018

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*M
Y = [0]*M
for m in range(M):
    P[m], Y[m] = map(int, input().split())
"""

N = int(input())

if N < 357:
    print(0)
    sys.exit()

ans_c = 0
num753 = 0
next_flag = False 
for n in range(357, N+1):
    next_flag = False
    nstr = str(n)
    
    if len(nstr) != sum(nstr.count(c) for c in '753'):
        continue        
    
    if all(nstr.count(c) for c in '753'):
            num753 = num753 + 1
print(num753)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
cnt = 0
for i in range(357, N+1):
  l = list(map(int, list(str(i))))
  a_3, a_5, a_7 = False, False, False
  flag = False
  for j in l:
    if j == 3:
      a_3 = True
    elif j == 5:
      a_5 = True
    elif j == 7:
      a_7 = True
    else:
      flag = True
  #print("3:{}, 5:{}, 7:{}".format(a_3, a_5, a_7))
  if flag == True:
    continue
  elif a_3 == a_5 == a_7 == True:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  2 20:06:49 2018

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*M
Y = [0]*M
for m in range(M):
    P[m], Y[m] = map(int, input().split())
"""

N = int(input())

if N < 357:
    print(0)
    sys.exit()

ans_c = 0
num753 = 0

for n in range(357, N+1):
    nstr = str(n)
    
    if all(nstr.count(c) for c in '753'):
        if len(nstr) == sum(nstr.count(c) for c in '753'):
            num753 = num753 + 1

print(num753)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

count=0
for i in range(N+1):
    SichiGoSan=1
    s=str(i)
    for number in [3,5,7]:
        if not str(number) in s:
            SichiGoSan=0
            continue

    if not SichiGoSan: continue

    for character in s:
        if not int(character) in [3,5,7]:
            SichiGoSan=0
            continue
    if not SichiGoSan: continue

    count+=SichiGoSan
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

count=0
for i in range(N+1):
    SichiGoSan=1
    s=str(i)
    for number in [3,5,7]:
        if not str(number) in s:
            SichiGoSan=0

    for character in s:
        if not int(character) in [3,5,7]:
            SichiGoSan=0

    count+=SichiGoSan
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

count = 0

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

print(count)
        

#これはTLEだ〜〜〜

Submission status: Time Limit Exceeded

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

for i in range(357, N+1):

    i_str = str(i)

    if i_str[0] != "3" and i_str[0] != "5" and i_str[0] != "7":
        continue
 
    else:
        thr = i_str.count("3")
        fiv = i_str.count("5")
        sev = i_str.count("7")


        if len(i_str) == thr + fiv + sev:
            if thr > 0:
                if fiv > 0:
                    if sev > 0: 
                        count += 1

print(count)

Submission status: Time Limit Exceeded

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

for i in range(357, N+1):

    i_str = str(i)

    if i_str[-1] != "3" and i_str[-1] != "5" and i_str[-1] != "7":
        continue
 
    else:
        thr = i_str.count("3")
        fiv = i_str.count("5")
        sev = i_str.count("7")


        if len(i_str) == thr + fiv + sev:
            if thr > 0:
                if fiv > 0:
                    if sev > 0: 
                        count += 1

print(count)

Submission status: Time Limit Exceeded

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

for i in range(357, N+1):

    i_str = str(i)
 
    thr = i_str.count("3")
    fiv = i_str.count("5")
    sev = i_str.count("7")


    if len(i_str) == thr + fiv + sev:
        if thr > 0:
             if fiv > 0:
                if sev > 0: 
                    count += 1

print(count)

Submission status: Time Limit Exceeded

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

for i in range(357, N+1):
 
    thr = str(i).count("3")
    fiv = str(i).count("5")
    sev = str(i).count("7")


    if len(str(i)) == thr + fiv + sev:
        if thr > 0:
             if fiv > 0:
                if sev > 0: 
                    count += 1

print(count)

Submission status: Time Limit Exceeded

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

for i in range(357, N+1):
 
    thr = str(i).count("3")
    fiv = str(i).count("5")
    sev = str(i).count("7")


    if thr > 0 and fiv > 0 and sev > 0 and len(str(i)) == thr + fiv + sev:
        count += 1

print(count)