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):
n = int(input())
ans = 0
def mask(i): return 1 << ((i-3) >> 1)
def dfs(a, use):
    global ans
    if a > n: return
    if use == 0b111: ans += 1
    for i in [3, 5, 7]: dfs(a*10+i, use | mask(i))

dfs(0, 0)
print(ans)

Solution (Python):
n = int(input())
ans = 0
def mask(i): return 1 << ((i-3) >> 1)
def dfs(a, use):
    global ans
    if a > n: return
    if use == 0b111: ans += 1
    for i in [3, 5, 7]: dfs(a*10+i, use | mask(i))

dfs(0, 0)
print(ans)

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


sys.setrecursionlimit(1000000)

plist = []


def dfs(p):
    if len(set(p)) == 3:
        plist.append(int(''.join(map(str, p))))
    if len(p) == 9:
        return
    dfs(p+[3])
    dfs(p+[5])
    dfs(p+[7])


dfs([])

ans = 0
for p in plist:
    if int(p) <= N:
        ans += 1
print(ans)

Solution (Python):
from itertools import product

n_str = input()
n = int(n_str)
l = len(n_str)

e_list = ["3", "5", "7"]

ans = 0
for i in range(3, l + 1):
    for temp in list(product(e_list, repeat=i)):
        
        if "3" in temp and "5" in temp and "7" in temp:
            num = int("".join(temp))
            if num <= n:
                ans += 1
print(ans)

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

def has_357(A):
    return '3' in A and '5' in A and '7' in A

def dfs(A):
    global count

    if A != '' and int(A) > N:
        return

    if has_357(A):
        count += 1

    for i in '357':
        A += i
        dfs(A)
        A = A[:-1]

    return count

print(dfs(''))

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):
import copy

n = int(input())


s = []
def dfs(A):
    if len(A) == len(str(n)):
        return
    for i in ['7', '5', '3']:
        A.append(i)
        if len(set(A)) == 3 and int(''.join(A)) <= n:
            s.append(int(''.join(A)))
        dfs(A)
        A.pop()

dfs([])


print(len(s))

Solution (Python):

from collections import deque

base = ["3", "5", "7"]
N = int(input())
q = deque(base)
ans = 0
while q:
    num = q.pop()
    for i in base:
        next = num + i
        if int(next) <= N:
            q.append(next)
            if next.count("3") and next.count("5") and next.count("7"): 
                ans += 1
print(ans)

Solution (Python):
n=int(input())
a1=["7","5","3"]
a2=[]
a3=[]
a4=[]
for i in range(len(str(n))-1):
    for j in range(len(a3)):
        a4.append(a3[j]+"3")
        a4.append(a3[j]+"5")
        a4.append(a3[j]+"7")
        a3.append(a3[j]+"3")
        a3.append(a3[j]+"5")
        a3[j]=a3[j]+"7"
    for j in range(len(a2)):
        if a2[j][1]=="3":
            a3.append(a2[j][0]+"3")
            a4.append(a2[j][0]+"3")
            a2.append([a2[j][0]+"5","3"])
            a2[j][0]=a2[j][0]+"7"
        if a2[j][1]=="5":
            a3.append(a2[j][0]+"5")
            a4.append(a2[j][0]+"5")
            a2.append([a2[j][0]+"7","5"])
            a2[j][0]=a2[j][0]+"3"
        if a2[j][1]=="7":
            a3.append(a2[j][0]+"7")
            a4.append(a2[j][0]+"7")
            a2.append([a2[j][0]+"5","7"])
            a2[j][0]=a2[j][0]+"3"
    for j in range(len(a1)):
        if a1[j][0]=="7":
            a2.append([a1[j]+"5","3"])
            a2.append([a1[j]+"3","5"])
            a1[j]=a1[j]+"7"
        if a1[j][0]=="5":
            
            a2.append([a1[j]+"7","3"])
            a2.append([a1[j]+"3","7"])
            a1[j]=a1[j]+"5"
        if a1[j][0]=="3":
            a2.append([a1[j]+"5","7"])
            a2.append([a1[j]+"7","5"])
            a1[j]=a1[j]+"3"
count=0
for i in reversed(range(0,len(a4))):
    if len(a4[i])<len(str(n)):
        break
    if int(a4[i])>n:
        count+=1
print(len(a4)-count)

Solution (Python):
import itertools

N = int(input())
ans = 0

shichigosan = ["3", "5", "7"]

for i in range(3, 11):
    shichi_nums = itertools.product(shichigosan, repeat=i)
    for nums in shichi_nums:
        
        num = "".join(nums)
        if "3" in num and "5" in num and "7" in num:
            num = int(num)
            if num <= N:
                
                ans += 1
            else:
                print(ans)
                quit()

Solution (Python):

from itertools import product
import sys


def solve(N: int):
    sN = str(N)
    ans = 0
    for i in range(1, len(sN) + 1):
        for p in product("357", repeat=i):
            if len(set(p)) == 3 and int("".join(p)) <= N:
                ans += 1
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    solve(N)


if __name__ == '__main__':
    main()

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())
total = set()
def check(x):
    if x.count('7') and x.count('5') and x.count('3'):
        return True
    else:
        return False

def dfs(a):
    if len(a) > len(str(n)):
        return

    for i in ['7', '5', '3']:
        a += i
        if int(a) <= n and check(a):
            total.add(a)
        dfs(a)
        a = a[:-1]


dfs('')
print(len(total))

Solution (Python):

import itertools
tmp = input()
siz = len(tmp)
N = int(tmp)

table = ['3','5','7']
cnt = 0 
for i in range(3, siz):
    
    for combi in itertools.product(table, repeat=i):
        
        cnt += 1 if len(set(combi)) == 3 else 0

for combi in itertools.product(table, repeat=siz):
    
    cur = 0
    for i,v in enumerate(combi[::-1]):
        cur += 10**i * int(v)
    
    
    if N >= cur:
        cnt += 1 if len(set(combi)) == 3 else 0
        

print(cnt)

Solution (Python):
def dfs(A, B):
    if len(A) > len(str(n)):
        return
    for i in sft:
        A.append(i)
        if int("".join(A)) <= n and ("3" in A) and ("5" in A) and ("7" in A):
            B.append("".join(A))
        dfs(A,B)
        A.pop()

if __name__ == "__main__":
    n = int(input())
    num_list = []
    ans_list=[]
    sft = ["3", "5", "7"]
    dfs(num_list,ans_list)
    print(len(ans_list))

Solution (Python):
def solve():
    N = int(input())
    print(dfs("",N, [False,False,False]))

def dfs(num, N, include):
    cnt = 0
    digit = ['7','5','3']

    for i in range(len(digit)):
        next_num = num + digit[i]
        next_include = include[:]
        next_include[i] = True
        if int(next_num) <= N:
            if next_include == [True,True,True]:
                cnt += 1
            cnt += dfs(next_num,N, next_include)
    
    return cnt
    
if __name__ == '__main__':
    solve()

Solution (Python):
c='753'
def dfs(s,L):
    global c
    li.append(s)
    if(len(s)==L):
        return
    for i in range(3):
        dfs(s+c[i],L)

N=int(input())
L=len(str(N))
li=[]
dfs('',L)
ans=0
for x in li:
    if(x==''):
        continue
    if(int(x)<=N and '7' in x and '5' in x and '3' in x):
        ans+=1
print(ans)

Solution (Python):

N = int(input())

q = list("357")


def dfs(X):
    if int(''.join(X)) > N:
        return 0

    res = 0
    if set(X) == set(q):
        res = 1

    for i in q:
        X.append(i)
        res += dfs(X)
        X.pop()
    
    return res



res = 0
for i in range(len(q)):
    res += dfs(list(q[i]))

print(res)

Solution (Python):
n=int(input())
l=('3','5','7')
def dfs(a,ans):
    if len(a)>=2 and int(''.join(a[1:]))>n:
      return ans
    for i in l:
        a.append(i)
        if all(j in a for j in l) and  int(''.join(a[1:]))<=n:
          ans+=1
        ans+=dfs(a,0)
        a.pop()
    return ans
print(dfs([0],0))

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


def dfs(A):
    if len(A)==len(str(N))+1:
        return 0
    
    cnt = 0
    if set(A) == set([3, 5, 7]):
            if int(''.join(map(str, A))) <= N:

                cnt = 1
                
    for i in [3, 5, 7]:
        A.append(i)
        cnt += dfs(A)
        A.pop()
    return cnt

cnt = 0
ans = dfs([])
print(ans)

Solution (Python):
def dfs(a):
    global ans
    if a>n:
        return
    if len(set(list(str(a))))==3:
        ans+=1
    for i in (3,5,7):
        a=a*10+i
        dfs(a)
        a//=10
    
n=int(input())
ans=0
dfs(0)
print(ans)

Solution (Python):

from itertools import*
n = int(input())
c = 0
k = "357"

for i in range(3, -~len(str(n))):
    for j in product(k, repeat = i):
        if all(j.count(h) for h in k):
            if int("".join(j)) <= n:
                c += 1
print(c)

Solution (Python):

n = int(input())

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

Solution (Python):
def func(cur, use):
  
  global counter
  if (cur > N): return 
  if (use == 0b111): counter += 1

  func(cur * 10 + 7, use | 0b001)
  func(cur * 10 + 5, use | 0b010)
  func(cur * 10 + 3, use | 0b100) 

N = int(input())
counter = 0
func(0, 0)
print(counter)

Solution (Python):
from collections import Counter
N = int(input())
M = [3, 5, 7]
num = []
def dfs(A):
    if A == "":
        pass    
    elif int(A) > N:
        return
    else:
        num.append(A)
    for v in M:
        A = A + str(v)
        dfs(A)
        A = A[:-1]
               
dfs("")
ans = []
for i in num:
    if len(Counter(i)) == 3:
        ans.append(i)
print(len(ans))

Solution (Python):
N = int(input())
M = len(str(N))
count = 0

def dfs(A):
  global count
  
  if len(A) <= M and (3 in A and 5 in A and 7 in A):
    num = 0
    for i in range(len(A)):
      num += A[i]*(10**i)
    if num <= N:
      count += 1
  elif len(A) > M:
    return

  for i in [3, 5, 7]:
    A.append(i)
    dfs(A)
    A.pop()
  
dfs([])
print(count)

Solution (Python):
n = input()
def dfs(A):
    
    global cnt
    if len(A) > len(n):
        return
    if len(A) >= 3 and int(A) <= int(n):
        if A.count('7') >= 1 and A.count('5') >= 1 and A.count('3') >= 1:
            cnt += 1
            
    for num in "357":
        A += num
        dfs(A)
        A = A[:-1]

cnt = 0
dfs("")
print(cnt)

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

def isOK(s):
    t = (''.join(s))
    if int(t) > n: return False
    f = True
    for i in [7, 5, 3]:
        if not str(i) in t: f = False
    return f

def dfs(s, res):
    if len(s) > 0 and int(''.join(s)) > n:
        return res
    for i in [3, 5, 7]:
        s.append(str(i))
        if isOK(s): res+=1
        res += dfs(s, 0)
        s.pop()
    return res
print(dfs([], 0))

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

def dfs(l):
    return sum([
        
        dfs(10 * l + i) if (10 * l + i) <= n else 0
        for i in [3, 5, 7]] +
        
        [1 if '3' in str(l) and '5' in str(l) and '7' in str(l) else 0]
        )

print(dfs(0))

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

ans = 0
while len(q) != 0:
    x = q.pop(0)
    for i in [ 3, 5 , 7]:
        y = 10 * x + i
        if ( y <= n):
            q.append(y)
            if '3' in str(y) and '5' in str(y) and '7' in str(y):
                ans += 1
print(ans)

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

def dfs(s, res):
  if int(s) > N:
    return 0
  res = +all((t in s)for t in '753')
  for i in '753':
    res += dfs(s+i, res)
  return res

print(dfs('0', 0))

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

l = len(str(10**9))
def dfs(A):
    global N
    if len(A)>0 and(int("".join(map(str, A)))>N):
        return 0
    
    ans = 0
    if(all(A.count(i)==0 for i in [0, 1, 2, 4, 6, 8, 9]) and (A.count(3) >0 and A.count(5) >0 and A.count(7) >0)):
        ans = ans + 1
    
    for i in [3, 5, 7]:
        A.append(i)
        ans = ans + dfs(A)
        A.pop()
    
    return ans
print(dfs([]))

Solution (Python):
import sys
import itertools

sys.setrecursionlimit(10**6)

def main():
    N = list(input())
    intN = int(''.join(N))
    lenN = len(N)
    set753 = ['7', '5', '3']
    ans = 0
    for n in range(3, lenN+1):
        tmp = itertools.product(set753, repeat=n)
        product = [x for x in tmp if len(set(x)) == 3]
        for s in product:
            if int(''.join(s)) <= intN:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import heapq

N=int(input())
count=0
que=[3,5,7]
heapq.heapify(que)
ans=[]
while True:
    x=heapq.heappop(que)
    if N>=x:
        count+=1
        ans.append(x)
    else:
        break
    heapq.heappush(que,10*x+3)
    heapq.heappush(que,10*x+5)
    heapq.heappush(que,10*x+7)

count=0
check=["3","5","7"]
for i in ans:
    for j in check:
        if str(i).count(j)==0:
            break
    else:
        count+=1

print(count)

Solution (Python):
from collections import deque
n = int(input())

li = [3, 5, 7]

def dfs():
  stack = deque()
  for i in li:
    stack.append(i)
  while stack:
    q = stack.popleft()
    if all(str(l) in str(q) for l in li):
      ans.append(q)
    for k in li:
      if q * 10 + k <= n:
        stack.append(q * 10 + k)
          
ans = []
dfs()
print(len(ans))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
res = 0


def resolve():
    n = int(input())

    def is_ok(L):
        l = "".join(L)
        if int(l) <= n:
            for i in ["7", "5", "3"]:
                if i not in l:
                    return False
            else:
                return True
        else:
            return False

    def dfs(L):
        global res
        if len(L) == len(str(n)):
            return

        for i in ["7", "5", "3"]:
            L.append(i)
            if is_ok(L):
                res += 1
            dfs(L)
            L.pop()

        return res

    print(dfs([]))


if __name__ == '__main__':
    resolve()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
nums = ['3', '5', '7']
cnt = 0

def dfs(cur, s):
    global cnt
    if len(cur) > 0 and '3' in cur and '5' in cur and '7' in cur:
        cnt += 1
    for c in nums:
        cur.append(c)
        if int(''.join(cur)) > int(s):
            return
        newcur = cur.copy()
        dfs(newcur, s)
        cur.pop()

def main():
    s = S()
    N = len(s)
    cur = []
    dfs(cur, s)
    print(cnt)

main()

Solution (Python):
n = int(input())
def dfs(s):
  if int(s) > n:
    return 0
  ret = 1 if all( (i in s) for i in '753') else 0
  for i in '753':
    ret+=dfs(s+i)
  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):
def dfs(s):
    if s != "":
        if int(s) > n:
            return 0
    if len(set(s)) == 3:
        cnt = 1
    else:
        cnt = 0
    for i in "753":
        cnt += dfs(s + i)
    return cnt


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

Solution (Python):
from itertools import product

n = int(input())
cnt = 0
for i in range(3, 10):
    for j in product(["3", "5", "7"], repeat=i):
        if len(set(j)) == 3:
            if int("".join(j)) <= n:
                cnt += 1
print(cnt)

Solution (Python):
def dfs(s):
    global cnt
    if s != "":
        if int(s) > n:
            return
    if len(set(s)) == 3:
        cnt += 1
    dfs(s + "3")
    dfs(s + "5")
    dfs(s + "7")


n = int(input())
cnt = 0
dfs("")
print(cnt)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


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
def I(): return int(input())
N = I()
ans = 0
kouho = set()
for i in range(1,10):
    for x in itertools.product('357',repeat=i):
        kouho.add(x)
for x in kouho:
    if len(set(x))==3 and int(''.join(x))<=N:
        ans += 1
print(ans)

Solution (Python):
def make_bscg(i, r, s):
    if i == r:
        return [s]
    ans = []
    ans += make_bscg(i+1, r, s+"3")
    ans += make_bscg(i+1, r, s+"5")
    ans += make_bscg(i+1, r, s+"7")
    return ans


def is_753(x):
    s, f, t = x.count("7"), x.count("5"), x.count("3")
    c = s + f + t
    return s >= 1 and f >= 1 and t >= 1 and c == len(x)
    

N = input()
nn = int(N)
broad_scg = [p for i in range(3, len(N)+1) for p in make_bscg(0, i, "")]
ans = 0
for bscg in broad_scg:
    if int(bscg) > nn:
        break
    if is_753(bscg):
        ans += 1
print(ans)

Solution (Python):
import itertools

s = input()
l = len(s)
N = int(s)

ans = 0
for i in range(3, l+1):
    for t in itertools.product("357", repeat = i):   
        if '3' in t and '5' in t and '7' in t and int(''.join(t)) <= N:
            ans += 1

print(ans)

Solution (Python):
import itertools
N = int(input())
ans = 0
for i in range(1, 10):
  for x in itertools.product("753", repeat=i):
    s= ''.join(x)
    if int(s) > N: continue
    if '3' not in s: continue
    if '5' not in s: continue
    if '7' not in s: continue
    ans += 1
print(ans)

Solution (Python):
from collections import deque
from collections import Counter
n=int(input())
if n<357:
    print(0)
    exit()
i=357
ans=0
while i<=n:
  c=Counter(str(i))
  if '3' in c and '5' in c and '7' in c:
    if c['3']+c['5']+c['7']==len(str(i)):
      ans+=1
  a=list(map(int,list(str(i))))
  a[-1]+=2
  j=-1
  while a[j]>7 and -j<len(a):
    a[j]=3
    a[j-1]+=2
    j-=1
  if a[0]>7:
    a[0]=33
  i=int(''.join(map(str,a)))

print(ans)

Solution (Python):
def dfs(i):
    for j in '753':
        y[i]=j
        if i ==0:
            z = y.copy()
            x.append(z)
        else:
            dfs(i-1)

n = input()
ans = 0
y=['']*len(n)
x=[]
for i in range(2,len(n)):
    dfs(i)
for i in x:
    if int(''.join(i))<=int(n) and len(set(list(''.join(i))))==3:
        ans+=1
print(ans)

Solution (Python):
OD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

N = int(input())
ans = 0
def dfs(i,before):
    global ans
    if all(before.count(i) > 0 for i in '357') and int(before) <= N:
        ans += 1
    if i == 10:
        return
    for s in '357':
        dfs(i + 1,before + s)
for s in '357':
    dfs(1,s)
print(ans)

Solution (Python):
def DFS(num):
    if 3<=len(num)<=m:
        if len(set(list(num)))==3:
            A.append(int(num))
    if len(num)<=m:
        for i in ["3","5","7"]:
            DFS(num+i)


n=input()
m=len(n)
A=[]
for i in ["3","5","7"]:
    DFS(i)

cnt=0
for i in A:
    if i<=int(n):
        cnt +=1
print(cnt)

Solution (Python):
def main():
    from collections import deque

    N = int(input())

    dq = deque([0])
    cnt = 0
    while dq:
        x = dq.popleft()
        if all(c in str(x) for c in '357'):
            cnt += 1
        for k in (3, 5, 7):
            nx = x * 10 + k
            if nx <= N:
                dq.append(nx)
    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
like_753 = []


def dfs(x):
    if n < x:
        return 0
    else:
        like_753.append(x)
        dfs(10*x+3)
        dfs(10*x+5)
        dfs(10*x+7)


dfs(3)
dfs(5)
dfs(7)

ls_753 = [x for x in like_753 if len(set(str(x))) == 3]
print(len(ls_753))

Solution (Python):
N=int(input())
ans=0
def dfs(cur,use):
    global ans
    if cur>N: return
    if use==0b111:ans+=1
    dfs(cur*10+7,use | 0b001)
    dfs(cur*10+5,use | 0b010)
    dfs(cur*10+3,use | 0b100)

dfs(0,0)
print(ans)

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

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

print(bfs('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):
def main():
    l = []
    l.append(list753from(3))
    l.append(list753from(5))
    l.append(list753from(7))
    flatten = lambda x: [z for y in x for z in (flatten(y) if hasattr(y, '__iter__') and not isinstance(y, str) else (y,))]
    l = flatten(l)
    
    
    print(len(list(filter(lambda x: ('3' in str(x)) & ('5' in str(x)) & ('7' in str(x)), l))))

def list753from(n):
    ret = []
    if n>N:
        return ret
    ret.append(n)
    a = list753from(int(str(n)+"3"))
    if a==[]:
        pass
    else:
        ret.append(a)

    a = list753from(int(str(n)+"5"))
    if a==[]:
        pass
    else:
        ret.append(a)

    a = list753from(int(str(n)+"7"))
    if a==[]:
        pass
    else:
        ret.append(a)

    return ret
    
    

if __name__ == '__main__':
    N = int(input())
    main()

Solution (Python):
import queue
q = queue.Queue()
n = int(input())
cnt = 0
q.put(3)
q.put(5)
q.put(7)
while not q.empty():
    tmp = q.get()
    if tmp <= n:
        if ('3' in str(tmp)) and ('7' in str(tmp)) and ('5' in str(tmp)):
            cnt += 1
        q.put(tmp*10 + 3)
        q.put(tmp*10 + 5)
        q.put(tmp*10 + 7)
    else:
        continue
print(cnt)

Solution (Python):

import itertools

n=int(input())

kn=len(str(n))

icnt=0
for kkn in range(3,kn+1):
    for i in itertools.product([3,5,7], repeat=kkn):
        if (3 in i) and (5 in i) and (7 in i):



            ni=int("".join(map(str,i)))

            if ni<=n:
                icnt+=1    
print(icnt)

Solution (Python):

import itertools

n=int(input())

kn=len(str(n))

icnt=0
for kkn in range(3,kn+1):
    for i in itertools.product([3,5,7], repeat=kkn):
        if (3 in i) and (5 in i) and (7 in i):
            ni=0
            for ii in i:
                ni=ni*10+ii

            if ni<=n:
                icnt+=1    
print(icnt)

Solution (Python):
from collections import deque

n = int(input())
nums = [3, 5, 7]

d = deque([0])

count = 0
while True:
    if len(d) == 0:
        break
    x = d.popleft()
    if x > n:
        continue
    else:
        if '3' in str(x) and '5' in str(x) and '7' in str(x):
            count += 1
        for num in nums:
            d.append(x * 10 + num)
print(count)

Solution (Python):
from collections import deque
N=int(input())
nums=["3","5","7"]
stack=deque(nums)
cnt=0
while stack:
    cand=stack.pop()
    if ('3' in cand) and ('5' in cand) and ('7' in cand):
        cnt+=1
    for c in nums:
        if int(cand+c)<=N:
            stack.append(cand+c)

print(cnt)

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

def dfs(num):
    if int(num)>n:
        return 0
    else:
        if num.count("3")>=1 and num.count("5")>=1 and num.count("7")>=1:
            ans=1
        else:
            ans=0
        
        for i in "753":
            ans=ans+dfs(num+i)
        return ans
        

print(dfs("0"))

Solution (Python):
import itertools
n=input()
ans=0

for i in range(3,len(n)+1):
    li=itertools.product([3,5,7],repeat=i)
    
    for j in li:
        t=''.join(map(str,j))
        
        if int(t)<=int(n):
            if t.count("3")>=1 and t.count("5")>=1 and t.count("7")>=1:
                ans+=1

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

S = ['3', '5', '7']
n = II()
cnt = 0

def dfs(ns, cnt):
    for s in S:
        news = ''.join([ns, s])
        
        if eval(news) > n:
            continue
        elif len(set(list(news))) != 3:
            
            cnt = dfs(news, cnt)
        else:
            cnt += 1
            
            cnt = dfs(news, cnt)
    return cnt


def solve():

    ans = dfs('', 0)
    print(ans)



if __name__ == '__main__':
    solve()

Solution (Python):
N=int(input())
ans=0
S=['']
flg=True
while flg:
  _S=[]
  for s in S:
    _S.append('3'+s)
    _S.append('5'+s)
    _S.append('7'+s)
  for _ in _S:
    if '3' in _ and '5' in _ and '7' in _:
      if int(_)<=N:
        ans+=1
      else:
        flg=False
  S=_S[:]
print(ans)

Solution (Python):
s=input()

def dfs(i):
    if int(i) > int(s):
        return 0
    res = 1 if all(i.count(c) > 0 for c in ("753")) else 0

    for t in "753":
        res += dfs(i+t)
    
    return res

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):
N=int(input())
def count753(s):
  if int(s)>N:
    return 0
  if all(s.count(c)!=0 for c in '753'):
    ret=1
  else:
    ret=0
  for i in '753':
    ret+=count753(s+i)
  return ret
print(count753('0'))

Solution (Python):
from itertools import product
from bisect import bisect_right
n = int(input())
ns = []
for i in range(9):
    for j in product(["7", "5", "3"], repeat=i + 1):
        ns.append(''.join(j))
ns = sorted([int(i) for i in ns if len(set(i)) == 3])
print(bisect_right(ns, n))

Solution (Python):
n=input()
if len(n)<3:
    print(0)
    exit()
dp=[[[[[0]*2 for _ in range(2)]for _ in range(2)] for _ in range(2)] for _ in range(len(n)+1)]
dp[0][0][0][0][0]=1
for i,c in enumerate(n):
  c=int(c)
  for l in range(2):
    for m in range(2):
      for s in range(2):
        for t in range(2):
          for j in [7,5,3]:
            if l==0 and c<j:
              continue
            dp[i+1][l or j<c][m or j==7][s or j==5][t or j==3]+=dp[i][l][m][s][t]
an=[0, 0, 0, 6, 36, 150, 540, 1806, 5796]
if len(n)==3:
  print(dp[-1][1][1][1][1]+dp[-1][0][1][1][1])
else:
  print(dp[-1][1][1][1][1]+dp[-1][0][1][1][1]+sum(an[3:len(n)]))

Solution (Python):
N = int(input())
from collections import deque

def solve(N):
    ans = 0
    d = deque([3,5,7])
    n = d.popleft()
    while n<=N:
        if len(set(list(str(n))))==3:
            ans += 1
        for num in [3,5,7]:
            new = int(str(n)+str(num))
            d.append(new)
        n = d.popleft()
    return ans
print(solve(N))

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

for i in range(3, len(str(N)) + 1):
  for ptn in itertools.product((3, 5, 7), repeat=i):
    if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
        continue
    a = int("".join(list(map(str, ptn))))
    if a <= N:
      ans +=1

print(ans)

Solution (Python):
n=int(input())
def f(s):
  if int(s) > n:
    return 0
  cnt = 1 if all(s.count(c) > 0 for c in '753') else 0 
  for c in '753':
    cnt += f(s + c)
  return cnt

print(f('0'))

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]




'''
N = ii()

shiki = [1]
for i in range(10):
    tmp = shiki[-1]*3
    shiki.append(tmp)

ele = [3, 5, 7]
l = []
for keta in range(3, 10):
    maxx = shiki[keta]
    for i in range(maxx):
        ten = 10**(keta-1)
        tmp = 0
        for j in reversed(range(keta)):
            tmp += ele[i//shiki[j]] * ten
            i %= shiki[j]
            ten //= 10
        l.append(tmp)

cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ['3', '5', '7']):
        cnt += 1
            
print(cnt)
'''

def n_shinsu(k, n):
    bi=''
    while n!=0:
        bi+=str(n%k)
        n=n//k
    return bi[::-1]

N = ii()
maxx = 8
l = []
ele = [3, 5, 7]
for keta in range(3, 10):
    maxx = (maxx+1) * 3 - 1
    for i in range(maxx):
        tmp = n_shinsu(3, i).zfill(keta)
        ten = 1
        num = 0
        for moji in tmp[::-1]:
            num += ele[int(moji)] * ten
            ten *= 10
        l.append(num)

cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ['3', '5', '7']):
        cnt += 1
            
print(cnt)