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

Solution (Python):
import itertools
import bisect

a = []
for i in range(3, 10):
    for j in itertools.product([3, 5, 7], repeat=i):
        if j.count(3) > 0 and j.count(5) > 0 and j.count(7) > 0:
            a.append(int("".join(map(str, j))))
a.sort()
n = int(input())
print(bisect.bisect_right(a, n))

Solution (Python):

"""
C - 755
TLE
"""
def gen_357():
    def conv(n):
        res = []
        while n:
            n, r = divmod(n, 4)
            if r == 0 and n:
                return '0'
            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)

Solution (Python):
def is753(num):
    d = str(num)
    if d.count("3") > 0 and d.count("5") > 0 and d.count("7") > 0:
        return(True)
    else:
        return(False)

def loop753(N, num):
    global counter
    if num <= N:
        if is753(num):
            counter += 1
    else:
        return

    loop753(N, num * 10 + 3)
    loop753(N, num * 10 + 5)
    loop753(N, num * 10 + 7)

counter = 0
NN = int(input())
loop753(NN, 0)
print(counter)

Solution (Python):
from itertools import product

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

  results = list()
  ans = 0

  for i in range(1, 10):
    for j in list(product(['3', '5', '7'], repeat=i)):
      results.append(''.join(map(str, list(j))))
  
  for result in results:
    if int(result) > N:
      break
    if '3' in result and '5' in result and '7' in result:
      ans +=1

  print(ans)


main()

Solution (Python):
N=raw_input()
l=len(N)
 
s="375"


def func(n):
	
	ret=0
	if len(n) == 0 :
		ret+=func(n+"3")
		ret+=func(n+"5")
		ret+=func(n+"7")
	elif  int(n)<=int(N):
		for i in s:
			if i not in n:
				ret=0
				break
		else:
			ret=1

		ret+=func(n+"3")
		ret+=func(n+"5")
		ret+=func(n+"7")
	return ret

print func("")

Solution (Python):
N=raw_input()

l=len(N)

s="375"

ans=0
def func(t):
	global ans
	
	if len(t)>len(N):
		return
	else:
		for si in s:
			if si not in t:
				break
		else:
			if int(t)<=int(N):
				ans+=1
	func(t+"3")
	func(t+"5")
	func(t+"7")

	return ans

print func("")

Solution (Python):
N=input()

l=len( str(N) )

s="357"

P=[ set() for i in range(l+1) ]   
P[0].add(0)

for i in range(1,l+1):
	k=l-i	
	for x in P[i-1]:
		for j in s:
			j=int(j)
			P[i].add(  x+(10**k)*j )
			P[i].add( 0 )


ans=0
for x in P[-1]:
	if  1<= x <= N:
		for i in s:
			if i not in str(x):
				break
		else:
			ans+=1

print ans

Solution (Python):
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'))

Solution (Python):
values = []


def dfs(n, x):
    if x <= n:
        str_x = str(x)
        if str_x.count('3') > 0 and str_x.count('5') > 0 and str_x.count('7') > 0:
            values.append(x)
    else:
        return

    if x <= 10 ** 9:
        dfs(n, 10 * x + 3)
        dfs(n, 10 * x + 5)
        dfs(n, 10 * x + 7)


def main():
    n = int(input())
    dfs(n, 0)
    print(len(values))


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

def dfs(n, a, b, c):
    if n > N: return 0
    ret = 1 if a and b and c else 0
    ret += dfs(n*10+3, True, b, c) + dfs(n*10+5, a, True, c) + dfs(n*10+7, a, b, True)
    return ret

print(dfs(0, False, False, False))

Solution (Python):
n = int(input())

def solve(s):
    if int(s) > n:
        return 0
    if '7' in s and '5' in s and '3' in s:
        count = 1
    else:
        count = 0
    count += solve(s + '7')
    count += solve(s + '5')
    count += solve(s + '3')
    return count

print(solve('0'))

Solution (Python):
def solve(N):
    stack = ["3", "5", "7"]
    count = 0

    while len(stack) > 0:
        s = stack.pop()
        if int(s) <= N: 
            count += int(all([c in s for c in "753"]))
            for c in "753":
                stack.append(s + c)
    return count
    

def main():
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

N = input()
n = int(N)

ret = 0
for x in range(3, len(N) + 1):
    for y in itertools.product('357', repeat=x):
        if len(set(y)) == 3 and int(''.join(y)) <= n:
            ret += 1
print(ret)

Solution (Python):
import itertools

N = int(raw_input())
count = 0

for i in range(3,10):
	for j in itertools.product("357", repeat=i):
		if int("".join(j))<=N and "7" in j and "5" in j and "3" in j:
			count += 1
print count

Solution (Python):
N = int(input())

S = [3, 5, 7]

now = N
l = 0

while now>0:
    l = l+1
    now = now//10    

for i in range(l-1):
    L = len(S)
    for j in range(L):
        tmp = S[j]*10+3
        S.append(tmp)
        tmp = S[j]*10+5
        S.append(tmp)
        tmp = S[j]*10+7
        S.append(tmp)
      
S2 = list(set(S))
S2.sort()
ans = 0
        
for i in S2:
    now = str(i)
    s3 = 0
    s5 = 0
    s7 = 0
    l2 = 0
    
    n = i
    
    while n>0:
        l2 = l2+1
        n = n//10
        
    for j in range(l2):
        if now[j]=='3':
            s3 = s3+1
        if now[j]=='5':
            s5 = s5+1
        if now[j]=='7':
            s7 = s7+1
    if s3*s5*s7>0 and s3+s5+s7==l2 and i<=N:
        ans = ans + 1
    elif i>N:
        break

print(ans)

Solution (Python):



def main():
    from itertools import product

    n = int(input())
    numbers = list()
    ans = 0

    for digit in range(1, 10):
        for i in list(product(['3', '5', '7'], repeat=digit)):
            numbers.append(''.join(map(str, list(i))))

    for number in numbers:
        if int(number) <= n:
            if '3' in number and '5' in number and '7' in number:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = input()
def ok(x):
    v = []
    while x > 0:
        v.append(x % 10)
        x /= 10
    return len(set(v)) == 3

def f(x):
    if x > n:
        return 0
    res = sum(f(10*x+i) for i in [7,5,3])
    if ok(x):
        res += 1
    return res
print(f(0))

Solution (Python):
s = [["3", "5", "7"]]
for i in range(8):
  t = []
  for x in s[i]:
    t += [x+"3", x+"5", x+"7"]
  s += [t]

n = int(input())
c = 0
for l in s:
  for x in l:
    if len(set(list(x))) == 3 and int(x) <= n:
      c += 1
print(c)

Solution (Python):
from itertools import product

def f(n):
    return 3**n - 3*(1 + 2**n - 2)

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

ans=0

if m>=4:
    for i in range(3,m):
        ans+=f(i)

for s in product(['7','5','3'],repeat=m):
    if len(set(s))==3 and int(''.join(s))<=n:
        ans+=1

print(ans)

Solution (Python):
def run(N):
    
    targets = make357(N)
    cnt = 0
    for t in targets:
        if all(t.count(s) for s in '357'):
            cnt += 1
    return cnt


def make357(N):
    '''
    3, 5 ,7のみを含むN以下の数を全列挙
    ただし文字列として格納
    '''
    targets = []
    targets_i = ['3', '5', '7']  
    for _ in range(1, len(str(N))):
        tmp = []
        for s in '357':
            tmp += [t + s for t in targets_i if int(t + s) <= N]
        targets_i = tmp
        targets += targets_i
    return targets


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


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
count = 0
def f(s):
  global count
  if int(s) > n:
    return
  if all(s.count(i) > 0 for i in "357"):
    count += 1
  for i in "357":
    f(s+i)
f("0")    
print(count)

Solution (Python):
import math
N=input()

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

Solution (Python):
import itertools
def calc_num(S,S_len):
  result = 0;
  l = [3,5,7];
  i = 3;
  while i <= S_len:
    for v in itertools.product(l,repeat=i):
      if int("".join(map(str,v))) <= S and list(set(v) & set(l)) == l:
        result = result + 1;
    i = i + 1;
  return result
  
S = list(map(int,input()));
S_len = len(S);
S = int("".join(map(str, S)));
result = calc_num(S,S_len);
print(result)

Solution (Python):
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"))

Solution (Python):
import itertools
a = int(input())
ar = ["3","5","7"]
c = 0
for i in range(3,len(str(a))+1):
    for j in itertools.product(ar,repeat=i):
        if j.count("3") >= 1 and j.count("5") >= 1 and j.count("7") >= 1:
            if a >= int("".join(list(j))):
                c += 1
print(c)

Solution (Python):
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'))

Solution (Python):
import itertools

N = int(input())
d753 = ["3", "5", "7"]

c = 0
for i in range(1, 10):
	for d in itertools.product(d753, repeat = i):
		if d.count("3") >= 1 and d.count("5") >= 1 and d.count("7") >= 1:
			x = int("".join(d))
			if x <= N:
				c += 1

print(c)

Solution (Python):
n = int(input())

def detector(str):
  
  if int(str) > n:
    return 0
  else:
    count = 0
    
    
    for i in "753":
      count += detector(str+i)
    
    if "3" not in str or "5" not in str or "7" not in str:
      return count
    else:
      return count + 1

print(detector("0"))

Solution (Python):
def solve(s):
    if int(s) > N:
        return 0

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

if __name__ == "__main__":
    N = int(input())
    print(solve('0'))

Solution (Python):

from sys import stdin

d_in = lambda: int(stdin.readline())  

cand = [0, 3, 5, 7]
N = d_in()


def check_count(count):
    if count[3] > 0 and count[5] > 0 and count[7] > 0:
        return True
    else:
        return False


def search(flag, nonzero, str_n, count):
    """
    flag : 現在の値がNと等しいか小さいか

    nonzero : 現在の値が0か否か

    str_n : 現在より小さい方の各桁を文字列として持つリスト

    count : {7: flag1, 5: flag2, 3: flag3}
    """
    if len(str_n) == 0:
        if check_count(count):
            return 1
        else:
            return 0
    elif check_count(count) and (not flag):
        return 3**(len(str_n))
    elif not flag:
        ans = 0
        for i in cand:
            if nonzero and i == 0:
                continue
            next_count = count.copy()
            next_count[i] += 1
            zeroflag = nonzero or (i != 0)
            ans += search(False, zeroflag, str_n[1:], next_count)
        return ans
    else:
        next_n = int(str_n[0])
        ans = 0
        for i in cand:
            if nonzero and i == 0:
                continue
            next_count = count.copy()
            if i > next_n:
                break
            elif i == 0:
                zeroflag = nonzero
                ans += search(False, zeroflag, str_n[1:], next_count)
            elif i == next_n:
                next_count[i] += 1
                ans += search(True, True, str_n[1:], next_count)
            else:
                next_count[i] += 1
                ans += search(False, True, str_n[1:], next_count)
        return ans


str_N = list(str(N))
cand_count = {0: 0, 3: 0, 5: 0, 7: 0}
print(search(True, False, str_N, cand_count))

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

count = 0
data = [3,5,7]
for i in range(3, len(str(N))+1):
    l = list(itertools.product(data, repeat=i))
    for j in range(len(l)):
        n = 0
        if 3 in l[j] and 5 in l[j] and 7 in l[j]:
            for keta in range(i-1,-1,-1):
                n += 10**keta * l[j][keta]
            if n <= N:
                count += 1
print(count)

Solution (Python):
n = int(input())

def make753(s):
    count = 0
    if int(s) >n:
        return 0
    if all(s.count(i) > 0 for i in '753'):
        count += 1
    for i in '753':
        count += make753(s + i)
    return count
        
print(make753('0'))

Solution (Python):
N = int(input())

elements = '753'

def dfs(S):
    if int(S) > N:
        return 0
    ans = 1 if all(S.count(element) for element in elements) else 0
    for element in elements:
        ans += dfs(S+element)
    return ans

print(dfs('0'))

Solution (Python):
N = int(input())


def dfs(s):
    if int(s) > N:
        return 0
    ret = 0
    for c in '753':
        ret += dfs(s+c)
    if '3' not in s or '5' not in s or '7' not in s:
        return ret
    return ret+1


print(dfs('0'))

Solution (Python):
import math

def count(target, digits, previous, candidates=[3,5,7]):
    if digits==0:
        nstr="{}".format(previous)
        chars=[int(c) for c in nstr]
        chars=set(chars)
        
        for c in candidates:
            if not c in chars:
                
                return 0

        return 1
    
    base = 10**(digits-1)
    ncases = 0
    for c in candidates:
        candidate = base*c + previous
        if candidate>target:
            continue
        ncases = ncases + count(target, digits-1, candidate) 
    return ncases
        
n=input()
ni=int(n)
ndigits=len(n)

ncases=0




for p in range(3,ndigits):
    for i in range(1,p-1):
        for j in range(1,p-i):

            ncases=ncases+int(math.factorial(p)/math.factorial(i)/math.factorial(j)/math.factorial(p-i-j))


ncases=ncases+count(ni,ndigits,0)
print(ncases)

Solution (Python):
A = []
def svt(now, count):
    A.append(now)
    if count > 10:
        return
    else:
        svt(now * 10 + 7, count + 1)
        svt(now * 10 + 5, count + 1)
        svt(now * 10 + 3, count + 1)

svt(3, 1)
svt(5, 1)
svt(7, 1)

A.sort()
N = int(input())
ans = 0
for i in A:
    j = str(i)
    a = 0
    b = 0
    c = 0
    for k in range(len(j)):
        if j[k] == "3":
            a = 1
        elif j[k] == "5":
            b = 1
        elif j[k] == "7":
            c = 1
    if a == 1 and b == 1 and c == 1 and i <= N:
        ans += 1
print(ans)

Solution (Python):
ans = 0
 
def dfs(s, n):
    global ans

    if s != "" and int(s) > n:
        return
    elif "3" in s and "5" in s and "7" in s:
        ans += 1

    for i in "753":
        dfs(s+i, n)

n = int(input())
dfs("", n)
print (ans)

Solution (Python):
from itertools import product
from bisect import bisect_left,bisect_right

st = '753'
ls = []
for i in range(3,10):
	s = list(product(st,repeat = i))
	for i in s:
		zz = ''.join(list(i))
		ls.append(zz)

arr = []
for i in ls:
	if '7' in i and '5' in i and '3' in i:
		arr.append(int(i))
arr.sort()
n = input()
print bisect_right(arr,n)

Solution (Python):
S = input()
N = int(S)


def count753(s):
    is753 = "7" in s and "5" in s and "3" in s
    if len(s) == len(S):
        return 1 if int(s) <= N and is753 else 0
    return int(is753) + count753(s + "7") + count753(s + "5") + count753(s + "3")


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

Solution (Python):
from bisect import bisect
T = list()
def make_list(i):
    number = ''
    n_4 = i
    while n_4 > 0:
        number = str(n_4 % 4) + number
        n_4 = n_4//4
    return number 
for n in range (0,3*10**5):
    number = make_list(n)
    if (('0' in number) or ('1' not in number) or ('2' not in number) or ('3' not in number)):
        continue
    number = number.replace('3','7')
    number = number.replace('2','5')
    number = number.replace('1','3')
    T.append(int(number))
N = int(input())
X = bisect(T,N)
print(X)

Solution (Python):
N = int(input())


def solve(x, t, f, s):
    if x > N:
        return 0

    res = 0
    if t and f and s:
        res += 1

    res += solve(x*10+3, t+1, f, s)
    res += solve(x*10+5, t, f+1, s)
    res += solve(x*10+7, t, f, s+1)

    return res


def main():
    print(solve(0, 0, 0, 0))


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

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

print(cnt('0'))

Solution (Python):
n =int(input())

def make753(s):
    if int(s) > n:
        return 0
    if all(s.count(i) > 0 for i in '753'):
        count = 1
    else:
        count = 0
    for i in '753':
        count += make753(s + i)
    return count
           
print(make753('0'))

Solution (Python):
n =int(input())
count = 0

def make753(s):
    global count
    if int(s) > n:
        return 0
    if all(s.count(i) > 0 for i in '753'):
        count += 1
    for i in '753':
        make753(s + i)
    return count
           
print(make753('0'))

Solution (Python):
from itertools import product
element = [3,5,7]

N = int(input())
ans = 0
for i in range(3, len(str(N)) + 1) :
    L = product(element, repeat=i)
    for candidate in L :
        if ((3 not in candidate) or (5 not in candidate) or (7 not in candidate)) :
            continue
        l = int("".join(list(map(str,candidate))))
        if l <= N :
            ans += 1
print(ans)

Solution (Python):
from bisect import  bisect

def convert(number) :
    if number == 0 :
        out = "0"
    else :
        out = ""
    while number > 0 :
        surplus = (number % 4)
        out = str(surplus) + out
        number //= 4
    return out

def seven_five_three(string) :
    string = string.replace("3","7").replace("2","5").replace("1","3")
    return string

L = []
for i in range(3*10**5) :
    l = convert(i)
    l = seven_five_three(l)
    if (("0" in l) or ("3" not in l) or ("5" not in l) or ("7" not in l)) :
        continue
    l = int(l)
    L.append(l)

N = int(input())
ans = bisect(L,N)
print(ans)

Solution (Python):
import numpy as np

def check(number):
    string = str(number)
    if("3" in string and "5" in string and "7" in string):
        if(number <= N):
            return 1
    return 0

def make_root_three(num):
    ans = 0
    i = 0
    while(num // 3):
        ans += (num % 3) * (10 ** i)
        num = num // 3
        i += 1
    ans += num * (10 ** i)
    return ans

def make_number_from_seed(seed, l):
    ans = 0
    string = str(seed).zfill(l)
    for i in range(l):
        ans += candidates[int(string[i])] * (10 ** i)
    return ans

N = int(input().strip())
length = int(np.log10(N)) + 1

candidates = [3, 5, 7]
ans = 0

for l in range(3, length + 1):
    for i in range(3**l):
        seed = make_root_three(i)
        number = make_number_from_seed(seed, l)
        ans += check(number)
    
print(ans)

Solution (Python):
n = int(input())
count = 0

def make753(s):
    global count
    if int(s) > n:
        return 0
    if all(s.count(i) > 0 for i in '753'):
        count += 1
    for i in '753':
        make753(s + i)
    return count
        
print(make753('0'))

Solution (Python):

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

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

Solution (Python):
n = int(input())

def recursive(s):
    if int(s) > n:
        return 0
    ret = 0
    if s.count('3')>0 and s.count('5')>0 and s.count('7')>0:
        ret = 1
    for c in '753':
        ret += recursive(s+c)
    return ret           

print(recursive('0'))

Solution (Python):
n = int(input())

def make753(s):
    count = 0
    if int(s) > n:
        return 0
    if all(s.count(i) > 0 for i in '753'):
        count += 1
    for i in '753':
        count += make753(s + i)
    return count

print(make753('0'))

Solution (Python):
def change_ten_to_kisu(num, kisu):      
    r = 0
    syo = num
    count = 0
    while syo >= kisu:
        r += (syo % kisu) * 10 ** count
        syo = syo // kisu
        count += 1
    return r + syo * 10 ** count

def change_kisu_to_ten(num, kisu):      
    n = str(num)
    r = 0
    for i in range(len(n)):
        r += int(n[-i - 1]) * kisu ** i
        
    return r

def plus(num):                   
    change = {"3" : "0", "5" : "1", "7" : "2"}
    change_r = {"0" : "3", "1" : "5", "2" : "7"}
    t = ""
    for i in str(num):
        t += change[i]
    r = change_ten_to_kisu(change_kisu_to_ten(int(t), 3) + 1, 3)
    if len(t) < len(str(r)):
        r = "0" + str(r)[1:]
    elif len(t) > len(str(r)):
        r = "0" * (len(t) - len(str(r))) + str(r)
    t = ""
    for i in str(r):
        t += change_r[i]
    return int(t)

N = int(input())

i = 3
count = 0
while i <= N:
    if "3" in str(i) and "5" in str(i) and "7" in str(i):
        
        count += 1
    i = plus(i)
print(count)

Solution (Python):
S = input()
threeS=""
flag=0
count=0
for s in S:
    if flag == 1:
        threeS = threeS + "3"
    elif s > "7":
        threeS = threeS + "3"
        flag=1
    elif s == "7":
        threeS = threeS + "3"
    elif s > "5":
        threeS = threeS + "2"
        flag=1
    elif s == "5":
        threeS = threeS + "2"
    elif s > "3":
        threeS = threeS + "1"
        flag=1
    elif s =="3":
        threeS = threeS + "1"
    else:
        if threeS == "":
            threeS = threeS + "0"
        else:
            threeS = threeS[0:-1] + str(max(0,int(threeS[-1:])-1))
            threeS = threeS + "3"
        flag=1

x=str(111)
count = 0

def add(s):
    if s == "":
        return "1"
    s = str( int(s)+1 )
    if s[-1:] == "4":
        s = add(s[:-1]) + "1"
    return s

while int(x) <= int(threeS):
    if "1" in x:
        if "2" in x:
            if "3" in x:
                count += 1
    x = add(x)

print(count)

Solution (Python):
n = int(input())

def make753(s):
    count = 0
    if int(s) > n:
        return 0
    if all(s.count(i) for i in '753'):
        count += 1
    for i in '753':
        count += make753(s + i)
    return count
    
print(make753('0'))

Solution (Python):
N = int(input())
num = ['3', '5', '7']
array = ['']
len_array = [0, 0, len(array)]
for i in range(len(str(N))):
    array.extend(array[len_array[1]:] * 3)
    len_array = [len_array[1], len_array[2], len(array)]
    for j in range(len_array[1], len_array[2]):
        diff_len = len_array[2] - len_array[1]
        for k in range(3):
            if k * diff_len // 3 + len_array[1] <= j < (k + 1) * diff_len // 3 + len_array[1]:
                array[j] += num[k]
array = [int(array[i]) for i in range(len(array)) if set(num) <= set(array[i])]
array = list(filter(lambda i: i <= N, array))
print(len(array))

Solution (Python):
import re

N = int(input())

numList = []
def plusNum(num, N):
    if num > N:
        return
    numList.append(num)
    for i in [3, 5, 7]:
        plusNum(int(str(num) + str(i)), N)

for num in [3, 5, 7]:
    plusNum(num, N)

ans = 0
for num in numList:
    num_str = str(num)
    count_3 = 0
    count_5 = 0
    count_7 = 0
    for i in range(len(num_str)):
        if num_str[i] == "3":
            count_3 += 1
        elif num_str[i] == "5":
            count_5 += 1
        elif num_str[i] == "7":
            count_7 += 1
        if count_3 >= 1 and count_5 >= 1 and count_7 >= 1:
            ans += 1
            break

print(ans)

Solution (Python):
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"))

Solution (Python):
N=int(input())

def keta(x, k):
    if x%10==x:
        return k
    else:
        y=x//10
        k+=1
        return keta(y,k)

ls_375_tmp=[]
def func(a, n, keta):
    if n==keta:
        return
    for num in ['3', '5', '7']:
        ls_375_tmp.append(int(num+a))
        func(num+a, n+1,keta)

keta_N=keta(N,1)
func('', 0, keta_N)

ct=0
for i in ls_375_tmp:
    if all(x in str(i) for x in ['3', '5', '7']) and i<=N:
        ct+=1
print(ct)

Solution (Python):
N = int(input())

ret = 0


def solve(seven=False, five=False, three=False, num=0):
    global ret
    if num <= N:
        if seven and five and three:
            ret += 1
        solve(True, five, three, num * 10 + 7)
        solve(seven, True, three, num * 10 + 5)
        solve(seven, five, True, num * 10 + 3)
    else:
        return


solve()
print(ret)

Solution (Python):
n = int(input())
def rec(s):
    if int(s) > n:
        return 0
    ans = 0
    if all(s.count(c) > 0 for c in "753"):
        ans = 1
    for c in "753":
        ans += rec(s+c)
    return ans
print(rec("0"))

Solution (Python):
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'))

Solution (Python):
N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    if (s.count('3')>0)and(s.count('5')>0)and(s.count('7')>0):
        ans = 1
    else:
        ans = 0
    for c in '753':
        ans += dfs(s + c)
    return ans
print(dfs('0'))

Solution (Python):
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'))

Solution (Python):
n = (int)(input())

def f(s):
    ans = 0
    if (int)(s) > n:
        return 0
    for c in '753':
        num = (str)(s+c)
        if (int)(num) <= n:
            if num.count('3')and num.count('5') and num.count('7'):
                ans += 1
            ans += f(num)
    return ans
print(f('0'))

Solution (Python):
from itertools import product
N = int(input())
dig = len(str(N))
ans = 0
for i in range(3,dig+1):
    for a in product('357',repeat=i):
        num = int("".join(a))
        if num > N:
            continue
        s = set(a)
        if not '3' in s:
            continue
        if not '5' in s:
            continue
        if not '7' in s:
            continue
        ans += 1

print(ans)

Solution (Python):
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'))

Solution (Python):
N=int(input())
count=0
def saiki(word):
    nums=['3','5','7']
    global count
    ans=0
    if(N==word):
        saiki(nums[0])
        saiki(nums[1])
        saiki(nums[2])
    elif(int(word)>N):
        return
    else:
        if '3' in word and '5' in word and '7' in word:
            count+=1
        saiki(word+nums[0])
        saiki(word+nums[1])
        saiki(word+nums[2])
        return
saiki(N)
print(count)

Solution (Python):

N = int(input())

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

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

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

print(dfs('0'))

Solution (Python):
import sys
sys.setrecursionlimit(100000)
N = int(input())
svt = []

def dfs(num):
    if num>1000000000:
        return
    
    
    else:
        svt.append(int(str(num)+'3'))
        dfs(int(str(num)+'3'))
        svt.append(int(str(num)+'5'))
        dfs(int(str(num)+'5'))
        svt.append(int(str(num)+'7'))
        dfs(int(str(num)+'7'))

def check753(num):
    exist3 = False
    exist5 = False
    exist7 = False
    s = str(num)
    for c in s:
        if c=='3':
            exist3 = True
        elif c=='5':
            exist5 = True
        elif c=='7':
            exist7 = True
    if exist3 and exist5 and exist7:
        return True
    else:
        return False


dfs(0)
svt = sorted(svt)
svt = svt[12:]

count = 0
for i in range(len(svt)):
    if svt[i]>N:
        break
    if check753(svt[i]):
        count += 1
print(count)

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


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

print(num)

Solution (Python):
N = int(input())
li = ['']
so = 0
for _ in range(9):
  l = len(li)
  for i in range(so, l):
    li.append(li[i] + '3')
    li.append(li[i] + '5')
    li.append(li[i] + '7')
  so = l
cnt = 0
for x in li:
  if '3' in x and '5' in x and '7' in x and int(x) <= N:
    cnt += 1
print(cnt)

Solution (Python):
N = int(input())

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

print(dfs("0"))

Solution (Python):
import math
n=int(input())
digitSize=2
while math.floor(n/(10**digitSize))>0:
    digitSize+=1


shime=[[],[],[],[357,375,537,573,735,753]]
def makeShime(nowDigitSize):
    shime.append([])
    for num in shime[nowDigitSize-1]:
        for i in range(nowDigitSize): 
            for j in (3,5,7): 
                newNum=math.floor(num/(10**i))*10+j
                newNum=newNum*(10**i)+num%(10**i)
                shime[nowDigitSize].append(newNum)
    shime[nowDigitSize]=list(set(shime[nowDigitSize]))
    shime[nowDigitSize].sort()
    if nowDigitSize<digitSize:
        makeShime(nowDigitSize+1)
makeShime(4)




i=0
sh=shime[digitSize]
le=len(shime[digitSize])
while True:
    if i>=le:
        break
    if n<sh[i]:
        break
    i+=1

cnt=i
for i in range(digitSize):
    cnt+=len(shime[i])
print(cnt)

Solution (Python):
n = int(input())

def dfs(s):
    count = 0
    sub_count = 0
    
    if int(s) > n:
        return 0
    
    for i in '753':
        if s.count(i) > 0:
            sub_count += 1
        if sub_count == 3:
            count += 1
        if i == '3':
            sub_count = 0
    
    for i in '753':
        count += dfs(s + i)
    
    return count

print(dfs('0'))

Solution (Python):


"""
解説参考
再帰関数で候補の数を作っていく版
"""

N = int(input())

def dfs(s):
    
    if int(s) > N:
        return 0
    
    if '7' in s and '5' in s and '3' in s:
        res = 1
    else:
        res = 0
    
    for c in '753':
        res += dfs(s + c)
    
    return res

print(dfs('0'))

Solution (Python):


from itertools import product

N = int(input())

cnt = 0

for prod in product(['0', '3', '5', '7'], repeat=9):
    
    num = int(''.join(prod))
    s = str(num)
    
    if (s.find('3') == -1 or s.find('5') == -1
            or s.find('7') == -1 or s.find('0') != -1):
        continue
    
    if num > N:
        continue
    cnt += 1
print(cnt)