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):
num753=[]
def checkall(n):
    flag = [0,0,0]
    while n > 0:
        if n % 10 == 3:
            flag[0] = 1
        elif n % 10 == 5:
            flag[1] = 1
        elif n % 10 == 7:
            flag[2] = 1
        else:
            pass
        n = n // 10
    return flag == [1,1,1]

def makelist(n,list1):
    if n > 10**9:
        return
    n3 = 10*n+3
    list1.append(n3)
    makelist(n3,list1)
    n5 = 10*n+5
    list1.append(n5)
    makelist(n5,list1)
    n7 = 10*n+7
    list1.append(n7)
    makelist(n7,list1)

makelist(0,num753)

N = int(input())
ans = 0
for x in num753:
    if x <= N and checkall(x):
        ans+=1
print(ans)

Solution (Python):
n = input()
l = list()
cnt = 0
def decide(digit,cur):
  if digit==0:
    l.append(cur)
    return
  decide(digit-1,cur+"3")
  decide(digit-1,cur+"5")
  decide(digit-1,cur+"7")
  return
for i in range(1,len(n)+1):
  decide(i,"")
n = int(n)
for x in l:
  if "3" not in x or "5" not in x or "7" not in x:
    continue
  if int(x)<=n:
    cnt += 1
print(cnt)

Solution (Python):
n = int(input())
a = ['3', '5', '7']

depth = len(str(n)) 
ans = 0

def search(s, i):
  if s != '':
    if int(s) <= n and '3' in s and '5' in s and '7' in s:
      global ans
      ans += 1
  if i != 0:
    for _a in a:
      search(s + _a, i - 1)

search('', depth)

print(ans)

Solution (Python):
from itertools import product
n=int(input())

ans = 0
for i in range(3, 10):
    for s in product('357', repeat=i):
        if len(set(s)) < 3:
            continue
        num = int(''.join(s))
        if  num > n:
            break
        ans += 1
print(ans)

Solution (Python):

from itertools import product

N_str = input()
len_N = len(N_str)
N = int(N_str)


dp = [[[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
      for _ in range(len_N)]



for l in range(len_N):
    dp[l][0][0][0][0] = 1



for m in range(10):
    digit_0 = int(N_str[0])
    if m > digit_0:
        continue
    if m in [3, 5, 7]:
        dp[0][digit_0 == m][m == 3][m == 5][m == 7] = 1


for l, m, n, o, p in product(range(len_N - 1), range(10), range(2), range(2),
                             range(2)):
    if m in [3, 5, 7]:
        digit_lp1 = int(N_str[l + 1])
        dp[l+1][0][n or m == 3][o or m == 5][p or m == 7] += \
            dp[l][0][n][o][p]

        if digit_lp1 < m:
            continue

        dp[l+1][digit_lp1 == m][n or m == 3][o or m == 5][p or m == 7] += \
            dp[l][1][n][o][p]

print(dp[-1][0][1][1][1] + dp[-1][1][1][1][1])

Solution (Python):
import itertools
n=int(input())
a=0
for i in range(3,len(str(n))+1):
    for p in itertools.product((3,5,7),repeat=i):
        if (3 in p)and(5 in p)and(7 in p):
            if int("".join(list(map(str,p))))<=n:
                a+=1
print(a)

Solution (Python):
def main():
    N = int(input())
    import itertools
    from bisect import bisect_left,bisect
    L=[]

    S = "753"
    m = 6
    for i in range(3,10):
        for j in itertools.product(S, repeat=i):
            flag7 = 0
            flag5 = 0
            flag3 = 0
            tmp = ""
            for s in j:
                if s == "7":
                    flag7 = 1
                elif s == "5":
                    flag5 = 1
                elif s == "3":
                    flag3 = 1
                tmp += s
            if flag3 == flag5 == flag7 == 1:
                tmp = int(tmp)
                L.insert(bisect_left(L,tmp), tmp)
    ans = bisect(L,N)
    print(ans)


main()

Solution (Python):
n=int(input())
cnt=0
l=['3','5','7']
def sol(x,c):
    global cnt
    if int(x)<=n and all(y in x for y in l):
        cnt+=1
    if c<9:
        for y in l:
            sol(x+y,c+1)
sol('0',0)
print(cnt)

Solution (Python):
from collections import deque

N = int(input())

stack = deque()
num_753 = 0


def dfs():
    global stack, num_753

    s = stack.pop()

    if int(s) > N:
        return

    is_contained = 1 if all(s.count(c) > 0 for c in '753') else 0
    num_753 += is_contained

    for next_s in '357':
        stack.append(s + next_s)


stack.append('0')
while stack:
    dfs()


print(num_753)

Solution (Python):

N = int(input())

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

print(rep('0'))

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

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

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

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

print(make_num('0'))

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

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

print(dfs('0'))

Solution (Python):
n = input()

def abc(s):
  t = all(('3' in s, '5' in s, '7' in s))
  if len(s) < len(n):
    return abc(s+'3') + abc(s+'5') + abc(s+'7') + t
  elif s <= n:
    return t
  else:
    return 0

print(abc(''))

Solution (Python):
N = int(input())
scg = ["3", "5", "7"]
s = []
res = []
s += scg
while len(s) > 0:
  p = s.pop()
  for i in range(3):
    q = p + scg[i]
    if int(q) <= N:
      s.append(q)
      tfs = [0, 0, 0]
      for i in range(len(q)):
        if q[i] == "3":
          tfs[0] = 1
        elif q[i] == "5":
          tfs[1] = 1
        elif q[i] == "7":
          tfs[2] = 1
      if min(tfs) != 0:
        res.append(q)
print(len(res))

Solution (Python):
import itertools

def seven_five_five(n):
    s = list(str(n))
    len_s = len(s)
    semi_753 = []
    for j in range(3,len_s+1):
        for i in itertools.product(['3','5','7'],repeat=j):
            l = ''.join(i)
            
            semi_753.append(l)

    target = [i for i in semi_753 if int(i) > 356 and int(i) <= n]
    
    count = 0
    for i in target:
        v = str(i)
        flag = [False,False,False]
        for j in list(v):
            if j == '7':
                flag[0] = True
            elif j == '5':
                flag[1] = True
            elif j == '3':
                flag[2] = True
            else:
                break

            if flag[0] and flag[1] and flag[2]:
                
                count += 1
                break
    print count
if __name__ == '__main__':
    n =  int(raw_input())
    seven_five_five(n)

Solution (Python):


N = int(input())

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

print(count753("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())
ln=len(str(n))
sft='7530'
cnt=0
def dfs(ln,s):
    global cnt
    if ln==0:
        if '7' in s and '5' in s and '3' in s:
            if '0' in str(int(s)):return
            if n>=int(s):cnt+=1
        return
    for e in sft:
        dfs(ln-1,s+e)
dfs(ln,'')

print(cnt)

Solution (Python):
N = input()
cnt = 0

if int(N) < 357:
    print(0)
    exit()

def solve(s):

    global cnt
    

    if len(s) >= 3:
        if int(s) > int(N):
            return

        n7 = s.count("7")
        n5 = s.count("5")
        n3 = s.count("3")

        if n7 >= 1 and n5 >= 1 and n3 >= 1 and n7+n5+n3 == len(s) and int(s) <= int(N):
            cnt += 1
        
    solve(s+"7")
    solve(s+"5")
    solve(s+"3")

solve("")
print(cnt)

Solution (Python):


import itertools

n = int(input().split()[0])
k = len(str(n))
c = 0

if k >= 3:
    for j in range(3, k+1):
        p_gen = itertools.product([3, 5, 7], repeat=j)
        for p in p_gen:
            x = 0
            for k_i in range(j):
                x += p[k_i] * 10**k_i
            if x <= n and len(set(list(str(x)))) == 3:
                c += 1

print(c)

Solution (Python):
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = input()
num = int(n)
l = len(n)
li = ['3', '5', '7']
keta = [[] for i in range(l)]
keta[0] = li
for i in range(1, l):
    for kazu in keta[i-1]:
        for n in li:
            keta[i].append(kazu + n)
ct = 0
for i in range(l):
    for n in keta[i]:
        if '3' in n and '5' in n and '7' in n and int(n) <= num:
            ct += 1
print(ct)

Solution (Python):
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce



def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



n, = map(int, input().split())

tmp = str(n)
length = len(tmp)

def dfs(cnt, num, sev, fiv, thr):
    if cnt == 0:
        return 1 if n >= num and sev*fiv*thr > 0 else 0

    sevp = dfs(cnt-1, num + 7*(10**(cnt-1)), sev + 1, fiv, thr)
    fivp = dfs(cnt-1, num + 5*(10**(cnt-1)), sev, fiv + 1, thr)
    thrp = dfs(cnt-1, num + 3*(10**(cnt-1)), sev, fiv, thr + 1)

    zerop = 0
    if num == 0:
        zerop = dfs(cnt - 1, num , sev, fiv, thr)

    return sevp + fivp + thrp + zerop

print(dfs(length, 0, 0, 0, 0))

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

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

dfs('0')
print(cnt)

Solution (Python):
n = int(input())
result = 0
q = list('753')
while q:
  s = q.pop(0)
  if int(s) > n:
    continue
  if all(s.count(c) > 0 for c in '753'):
    result += 1
  q.extend([s + c for c in '753'])
print(result)

Solution (Python):
n = int(input())
result = 0
q = list('753')
while q:
  s = q.pop()
  if int(s) > n:
    continue
  if all(s.count(c) > 0 for c in '753'):
    result += 1
  q.extend([s + c for c in '753'])
print(result)

Solution (Python):
N = input()
l = ['3', '5', '7']
L = ['3', '5', '7']
temp = []
d = len(N)
N = int(N)


if N - 357 < 0:
    print(0)
    exit()


a = 0
for i in range(3, d):
    a += 3 ** i - 3 * (2 ** i - 2) - 3


for k in range(d - 1):
    for i in L:
        for j in l:
            temp.append(i + j)
    L.clear()
    L.extend(temp)
    temp.clear()
L = [i for i in L if '3' in i and '5' in i and '7' in i]

count = 0
for i in L:
    if int(i) <= N:
        count += 1
print(a + count)

Solution (Python):
import heapq
import sys
import collections
input = sys.stdin.readline

def solve():
  n = int(input())
  query = collections.deque([3,5,7])
  template = []
  while query:
    tmp = query.popleft()
    tmp3 = str(tmp*10+3)
    if tmp3.count("3") and tmp3.count("5") and tmp3.count("7"):
      template.append(int(tmp3))
    tmp5 = str(tmp*10+5)
    if tmp5.count("3") and tmp5.count("5") and tmp5.count("7"):
      template.append(tmp5)
    tmp7 = str(tmp*10+7)
    if tmp7.count("3") and tmp7.count("5") and tmp7.count("7"):
      template.append(tmp7)
    if int(tmp3) <= n:
      query.append(int(tmp3))
    if int(tmp5) <= n:
      query.append(int(tmp5))
    if int(tmp7) <= n:
      query.append(int(tmp7))
  template2 = list(set(template))
  ans = 0
  for i in template2:
    if int(i) <= n:
      ans += 1
  print(ans)
   
      
    
solve()

Solution (Python):
N = int(input())
 
def search(i,j,k,val) :
    ret = 0 
    if val > N :
        return 0
    elif i > 0 and j > 0 and k > 0 and val<=N:
        ret = 1 
    else :
        ret = 0 
    ret += search(i+1,j,k,val*10+3)
    ret += search(i,j+1,k,val*10+5)
    ret += search(i,j,k+1,val*10+7)
    return ret
print(search(0,0,0,0))

Solution (Python):
X=input()
lst = [int(s) for s in list(X)]
N=len(lst)
X=int(X)
ans=0

for i in range(3,N):
  ans+=(3**i-3*(2**i)+3)

ls=[7,5,3]
for i in range(1,N):
  ls_3=[10*s+3 for s in ls]
  ls_5=[10*s+5 for s in ls]
  ls_7=[10*s+7 for s in ls]
  ls=ls_3+ls_5+ls_7
 
def judge(n):
  if n>X:
    return 0
  else:
    if(('3' in str(n))and('5' in str(n))and('7' in str(n))):
      return 1
    else:
      return 0
for t in ls:
  ans+=judge(t)
print(ans)

Solution (Python):
import itertools
n = int(input())
ls = ["3", "5", "7"]
cnt = 0
for i in range(3, len(str(n)) + 1):
    for j in itertools.product(ls, repeat=i):
        if "3" in j and "5" in j and "7" in j:
            t = ""
            for k in j:
                t += k
            if 1 <= int(t) <= n:
                cnt += 1
print(cnt)

Solution (Python):
import itertools

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

    num = ['3','5','7']
    num_list = set()

    for a in num:
        for b in num:
            for c in num:
                num_list.add(a+b+c)
                for d in num:
                    num_list.add(a+b+c+d)
                    for e in num:
                        num_list.add(a+b+c+d+e)
                        for f in num:
                            num_list.add(a+b+c+d+e+f)
                            for g in num:
                                num_list.add(a+b+c+d+e+f+g)
                                for h in num:
                                    num_list.add(a+b+c+d+e+f+g+h)
                                    for i in num:
                                        num_list.add(a+b+c+d+e+f+g+h+i)

    cnt = 0
    for i in num_list:
        if i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1:
            if int(i) <= N:
                cnt += 1

    print(cnt)
    

main()

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

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

print(dfs("0"))

Solution (Python):
n=int(input())
def f(x):
	if int(x)>n:return 0
	else:return all(d in x for d in"357")+f(x+"3")+f(x+"5")+f(x+"7")
print(f("0"))

Solution (Python):
n=int(input())
def dfs(x):
	if int(x)>n:
		return 0
	else:
		return all(d in x for d in "357")+dfs(x+"3")+dfs(x+"5")+dfs(x+"7")
print(dfs("0"))

Solution (Python):

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline


N = int(input())

def dfs(next_value, value, count_flag, count):
    value += next_value
    int_value = int(value)



    if int_value > N:
        return count

    if int_value >= 357:
        if count_flag == False:
            if len(set(list(value))) == 3:
                count_flag = True

        if count_flag:
            count += 1

    count = dfs('3', value, count_flag, count)
    count = dfs('5', value, count_flag, count)
    count = dfs('7', value, count_flag, count)

    return count


count = 0
value = ''

count = dfs('3', '', False, count)
count = dfs('5', '', False, count)
count = dfs('7', '', False, count)

print(count)

Solution (Python):
import itertools
n = input()
length = len(n)
n = int(n)

num_list = []
for i in range(length,2,-1):
    l = list(itertools.product(['3','5','7'],repeat = i))
    l = [int(''.join(i)) for i in l if len(set(i)) == 3 ]
    num_list.extend(l)
    
num_list = [i for i in num_list if i <= n]

print(len(num_list))

Solution (Python):

N = int(input())

ketalis = list(str(N))
ketalis.reverse()

dp = []

for i in range(10):

    a = []

    for i2 in range(2):
        b = []

        for i3 in range(2):
            c = []

            for i4 in range(2):
                d = []

                for i5 in range(2):
                    e = []

                    for i6 in range(2):

                        e.append(-1)

                    d.append(e)

                c.append(d)

            b.append(c)
            
        a.append(b)

    dp.append(a)

dp[0][0][0][0][0][0] = 1




for i in range(10):

    if i == 0:
        continue;

    keta = 10 - i

    nowketa = 0

    if len(ketalis) >= keta:

        nowketa = int(ketalis[keta-1])


    for sf in range(2):

        for ff in range(2):

            for tf in range(2):

                for mnf in range(2):

                    for mxf in range(2):

                        for x in [0,3,5,7]:

                            if dp[i-1][sf][ff][tf][mnf][mxf] == -1:
                                continue;


                            nsf = sf
                            nff = ff
                            ntf = tf
                            nmnf = mnf
                            nmxf = mxf


                            if x == 0 and mxf == 1: 
                                continue;

                            if x != 0 and mxf == 0: 
                                nmxf = 1

                            if mnf == 0:

                                if x > nowketa:
                                    continue;

                                if x < nowketa:
                                    nmnf = 1

                            if x == 7:
                                nsf = 1
                            if x == 5:
                                nff = 1
                            if x == 3:
                                ntf = 1

                            if dp[i][nsf][nff][ntf][nmnf][nmxf] == -1:
                                dp[i][nsf][nff][ntf][nmnf][nmxf] = 0

                            dp[i][nsf][nff][ntf][nmnf][nmxf] += dp[i-1][sf][ff][tf][mnf][mxf]

print (max(0,max(0,dp[-1][1][1][1][0][1]) + max(0,dp[-1][1][1][1][1][1])))

Solution (Python):
import itertools
s = input()
n = int(s)
l = len(s)
lst = []
for i in range(3, l + 1):
    lst += list(itertools.product([3, 5, 7], repeat=i))
lst = [x for x in lst if 3 in x]
lst = [x for x in lst if 5 in x]
lst = [x for x in lst if 7 in x]
lst = [int("".join(map(str, x))) for x in lst]
lst = [x for x in lst if x <= n]
print(len(lst))

Solution (Python):
a = []

def h(t):
  return 3 in t and 5 in t and 7 in t

def comb(t):
  l = 0
  for i in t:
    l += i
    l = l * 10
  return l // 10

import itertools

for i in range(10):
  a += [comb(x) for x in list(itertools.product([3, 5, 7], repeat=i)) if h(x)]

n = int(input())

t = 0

for i in a:
  if i <= n:
    t += 1

print(t)

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N = I()

def dfs(s):
    if int(s)>N:
        return 0
    else:
        if all(s.count(c)>=1 for c in ['3','5','7']):
            ret = 1
        else:
            ret = 0
        for x in ['3','5','7']:
            ret += dfs(s+x)
        return ret

print(dfs('0'))

Solution (Python):
def main():
    N = int(input())
    if N < 357: return 0

    cur = ["3", "5", "7"]
    count = 0
    while cur:
        temp = []
        for s in cur:
            if "3" in s and "5" in s and "7" in s:
                count += 1
            for c in "357":
                if int(c+s) <= N:
                    temp.append(c+s)
        cur = temp
    return count

if __name__ == '__main__':
    print(main())

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

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

print(dfs('0'))

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


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

  return ret


print(dfs('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())
cnt = 0
for i in range(3,10):
    for m in product(["3","5","7"],repeat = i):
        if "3" in m and "5" in m and "7" in m and int("".join(m))<=n:
            cnt += 1
print(cnt)

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

def dfs(num, cnt):
  if num > n: return 0
  str_num = str(num)
  ret = 0
  if ('7' in str_num) and ('5' in str_num) and ('3' in str_num):
    ret = 1
  
  ret += dfs(int(str_num + '7'), cnt)
  ret += dfs(int(str_num + '5'), cnt)
  ret += dfs(int(str_num + '3'), cnt)
  return ret
ans = dfs(0,0)
print(ans)

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

def solve(s):
    global count
    if int(s) > n:
        return

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

    for c in '753':
        solve(s + c)

solve('0')
print(count)

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

def shichigosan(x):
  if x == "":
    r = 0
    r += shichigosan(x+"3")
    r += shichigosan(x+"5")
    r += shichigosan(x+"7")
    return r
  else:
    if int(x) > N:
      return 0
    else:
      r = 0
      if '3' in x and '5' in x and '7' in x:
        r = 1      
      r += shichigosan(x+"3")
      r += shichigosan(x+"5")
      r += shichigosan(x+"7")
      return r
        
print(shichigosan(""))

Solution (Python):
def make_good_753(a,digit):
    ans_list = []
    str_list = ["7","5","3"]
    for i in range(digit):
        ans_list.append(a%3)
        a //= 3
    ans_list.reverse()
    ans_list = [ str_list[i] for i in ans_list]
    if set(ans_list) == {'7', '3', '5'}:
        return int("".join(ans_list))
    else:
        return None

candidate_list = []
n = int(input())
for i in range(3,10):
    for j in range(3**i):
        candidate = make_good_753(j,i)
        if candidate != None:
            if candidate <= n:
                candidate_list.append(candidate)
print(len(candidate_list))

Solution (Python):
import sys
input=sys.stdin.readline

N = int(input())

def is753(s):
    return all(s.count(c) > 0 for c in "753")

a = []
def f(s):
    if int(s) > N:
        return
    if is753(s):
        a.append(s)
    for c in "753":
        f(str(int(s+c)))
f("0")


ans = 0
for s in a:
    ans += 1 if is753(s) else 0

print(ans)

Solution (Python):
import itertools


def solve():
    n = int(input())
    c = 0
    for i in range(3, len(str(n)) + 1):
        for v in itertools.product(["3", "5", "7"], repeat=i):
            num = int("".join(v))
            if is_good(num) and num <= n:
                c += 1
    return c


def is_good(i):
    return set(str(i)) == {"3", "5", "7"}


if __name__ == "__main__":
    print(solve())

Solution (Python):
import math
n_in = int(input())


def sgs(n, a, s, s_temp):
    if a == math.ceil(math.log(n, 10)):
        c = 0
        for i in s:
            i_listed = list(map(int, list(str(i))))
            if 3 in i_listed and 5 in i_listed and 7 in i_listed:
                if i <= n:
                    c += 1
    else:
        a += 1
        temp = []
        for i in s_temp:
            s.append(10 * i + 3)
            s.append(10 * i + 5)
            s.append(10 * i + 7)
            temp.append(10 * i + 3)
            temp.append(10 * i + 5)
            temp.append(10 * i + 7)
        s_temp = temp
        c = sgs(n, a, s, s_temp)
    return c


ans = sgs(n_in, -1, [3, 5, 7], [3, 5, 7])
print(ans)

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

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

ans = 0

for i in range(4**len(str(n))):
    cnt = Base_10_to_n(i, 4)

    if cnt.count("0") != 0 or (cnt.count("1") == 0 or cnt.count("2") == 0 or cnt.count("3") == 0):
        continue

    temp = []
    for j in range(len(cnt)):
        if cnt[j] == "1":
            temp.append("3")
        elif cnt[j] == "2":
            temp.append("5")
        elif cnt[j] == "3":
            temp.append("7")
    num = int("".join(temp))

    if num <= n:
        ans += 1
print(ans)

Solution (Python):
import itertools
n=str(input())
ans=0
for i in range(3,len(n)+1):
    for j in itertools.product([3,5,7], repeat=i):
        if (3 not in j) or (5 not in j) or (7 not in j):
            continue
        a=''.join(list(map(str,j)))
        if int(a)<=int(n):
            ans+=1
print(ans)

Solution (Python):

import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n = list(map(lambda c: ord(c) - ord('0'), input()))



def solve(pos, leading_zero, is_small, i3, i5, i7):

    

    if pos == len(n):
        if i3 and i5 and i7:
            return 1
        return 0

    res = 0

    for d in [0,3,5,7]:
        if leading_zero == False and d == 0:
            continue
        if not is_small and d > n[pos]:
            continue
        new_is_small = True
        if d == n[pos] and not is_small: new_is_small = False
        new_leading_zero = False
        if leading_zero and d == 0:
            new_leading_zero = True
        res += solve(pos + 1, new_leading_zero, new_is_small,
                     i3 or (d == 3), i5 or (d == 5), i7 or (d == 7))

    return res


print(solve(0, True, False, False, False, False))

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


def dfs(x: str):
    if int(x) > n:
        return
    if x.count('3') >= 1 and x.count('5') >= 1 and x.count('7') >= 1:
        global ans
        ans += 1

    dfs(x+'3')
    dfs(x+'5')
    dfs(x+'7')


dfs('0')
print(ans)

Solution (Python):
nums = ['7','5','3']
N = input()
Max_digit = len(N)

def generator(n, nums):
    """
    return n-digit number in strings that are made out of numbers in nums and each one use precisely once
    """
    ans = [x for x in nums]
    
    for idx in range(1,n):
        new_ans = []
        for n1 in ans:
            for n2 in nums:
                new_ans.append(n1 + n2)
        ans = new_ans.copy()
    
    return [x for x in ans if all(num in x for num in nums)]

if Max_digit < 3:
    print(0)
if Max_digit == 3:
    ans = generator(3,nums)
    print(len([x for x in ans if int(x) <= int(N)]))
if Max_digit > 3:
    
    counter = 0
    for d in range(3, Max_digit):
        counter += len(generator(d,nums))
    
    ans = generator(Max_digit, nums)
    counter += len([x for x in ans if int(x) <= int(N)])
    print(counter)

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

Solution (Python):
n = input()

d_len = len(n)


def dfs(d):
    ret = 0
    if int(d) > int(n):
        return 0
    if all(i in d for i in ('357')):
        ret += 1
    for j in '357':
        ret += dfs(d + j)
    return ret


print(dfs('0'))

Solution (Python):
from itertools import product
N = input()
ans = 0
for i in range(3,len(N)+1):
    for k in product(["3","5","7"],repeat=i):
        if k.count("3") > 0 and k.count("5") > 0 and k.count("7") > 0:
            if int(''.join(k)) <= int(N):
                ans += 1
print(ans)

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

def dfs(s):
    if int(s) > N:
        return 0
    r = 1 if s.count("3")>0 and s.count("5")>0 and s.count("7")>0 else 0
    for x in ["3","5","7"]:
        r += dfs(s+x)
    return r

print(dfs("0"))

Solution (Python):
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

sys.setrecursionlimit(10000)

mod = 1000000007

"""

a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 



    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())


    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  
"""


if __name__ == "__main__":
    N = int(sys.stdin.readline())
    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 = input()

l = len(N)
ans = 0

for n in range(1, 4**l):
  n4 = ""
  while n > 0:
    mod = n % 4
    n4 = str(mod) + n4
    n //= 4
  
  if "0" in n4:
    continue
  
  if ("1" in n4) and ("2" in n4) and ("3" in n4):
    n4_10 = ""
    for i in range(len(n4)):
      if n4[i] == "1":
        n4_10 = n4_10 + "7"
      elif n4[i] == "2":
        n4_10 = n4_10 + "5"
      else:
        n4_10 = n4_10 + "3"
    if int(n4_10) <= int(N):
      ans += 1

print(ans)

Solution (Python):
import itertools
n = input()
lst = list("357")
cnt = 0
for i in range(3, len(n) + 1):
    for j in itertools.product(lst, repeat=i):
        if int("".join(j)) <= int(n) and "3" in j and "5" in j and "7" in j:
            cnt += 1
print(cnt)

Solution (Python):
n = input()
count = 0
def f(s):
    if s == "":
        ns = 0
    else:
        ns = int(s)
    
    if ns <= int(n):
        s3 = s.count("3")
        s5 = s.count("5")
        s7 = s.count("7")
        if s3>0 and s5>0 and s7>0 and s3+s5+s7 == len(s):
            global count
            count += 1
        f(s+"3")
        f(s+"5")
        f(s+"7")
f("")
print(count)

Solution (Python):
n = int(input())
def check(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 += check(s+i)
    return count
print(check('0'))

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