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())
n = ("7","5","3")
def dfs(a):
    global ans
    if int(a) > N:
        return 0
    if set(n) == set(a):
        ans += 1
    for i in range(3):
        dfs(a+n[i])

ans = 0
for i in range(3):
    dfs(n[i])
print(ans)

Solution (Python):
def rec(s):
    if s and int(s) > n:
        return 0

    res = 0
    if all(c in s for c in '753'):
        res += 1
    for c in '753':
        res += rec(s + c)
    return res


n = int(input())
print(rec(''))

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
values = []
def dfs(s):
    if s != '':
        if int(s) > N:
            return None
    values.append(s)
    dfs(s+'3')
    dfs(s+'5')
    dfs(s+'7')
dfs('')
for e in values:
    if '3' in e and '5' in e and '7' in e:
        count += 1
print(count)

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


def func(s):
    if int(s) > n:
        return 0
    count = 1 if all(s.count(l) for l in "357") else 0
    for l in "357":
        count += func(s+l)
    return count


print(func("0"))

Solution (Python):
from collections import deque
s = input()
n = len(s)
s = int(s)
if n<3:
    print(0)
    exit()
nums = deque(['7','5','3'])
kouho= deque()
while nums:
    num = nums.popleft()
    num3 = num+'3'
    num5 = num+'5'
    num7 = num+'7'
    if (3<= len(num3) <= n):
        kouho.append(num3)
        kouho.append(num5)
        kouho.append(num7)
    if len(num3)<n:
        nums.append(num3)
        nums.append(num5)
        nums.append(num7)

ans = 0
while kouho:
    number = kouho.pop()
    if ("3" in number)and("5" in number)and("7" in number):
        if int(number)<=s:
            ans +=1
print(ans)

Solution (Python):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *

from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

S = input().rstrip()
N = len(S)

def dfs(num):
    if len(num) == N:
        return 1 if '3' in num and '5' in num and '7' in num and 1 <= int(num) <= int(S) else 0

    ret = 0
    if len(num) == 0 or '3' not in num and '5' not in num and '7' not in num:
        ret += dfs(num+'0')
        ret += dfs(num+'3')
        ret += dfs(num+'5')
        ret += dfs(num+'7')
    else:
        ret += dfs(num+'3')
        ret += dfs(num+'5')
        ret += dfs(num+'7')

    return ret

def main():
    """ main """
    print(dfs(''))

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
N_ = input()
N = int(N_) 
n = len(list(N_)) 


A = ['3','5','7']

ans = 0
if(n >= 3): 
 for i in range(3,n+1):
  Comb = list(itertools.product(A, repeat=i)) 
  
  for j in range(len(Comb)):
   tmp = list(Comb[j])
   
   judge = 1 
    
   
   tmp_num = ''
   for k in range(len(tmp)):
     tmp_num += tmp[k]
   tmp_num = int(tmp_num)
   if(tmp_num > N):
      judge = 0
   
    
   
   three,five,seven = 0,0,0
   for k in range(len(tmp)):
     if(tmp[k]=='3'): three += 1
     elif(tmp[k]=='5'): five += 1
     elif(tmp[k]=='7'): seven += 1
   if(three*five*seven == 0): 
    judge = 0
   
   
   if(judge == 1): 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())

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):
n=int(input())

def ju(n):
    l=list(str(n))
    j=[0]*3
    f=0
    for i in range(len(l)):
        if l[i]=='3':
            j[0]=1
        elif l[i]=='5':
            j[1]=1
        elif l[i]=='7':
            j[2]=1
        else:
            f=1
    if sum(j)==3 and f==0:
        return 1
    else:
        return 0

zenbu=[3,5,7]

for i in range(8):
    tmp=[]
    for j in zenbu:
        tmp.append(j+3*(10**(i+1)))
        tmp.append(j+5*(10**(i+1)))
        tmp.append(j+7*(10**(i+1)))
        tmp.append(j)
    zenbu=tmp
  
ans=0
for i in zenbu:
    if i<=n and ju(i)==1:
        ans+=1
print(ans)

Solution (Python):
N = int(input())
def shime(s):
    if int(s) > N:
        return 0
    if '7' in s and '5' in s and '3' in s:
        tmp = 1
    else:
        tmp = 0
    tmp += shime(s+'7')
    tmp += shime(s+'5')
    tmp += shime(s+'3')
    return tmp
print(shime('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):
import math
n = int(input())
keta = int(math.log10(n))+1

num_list = []

def append_number(n):
    numbers = []
    for s in [3,5,7]:
        numbers.append(str(n)+str(s))
    return numbers

def make_numbers(n_list,keta):
    if keta == 0:
        return n_list
    else:
        append_numbers = []
        for n in n_list:
            for s in append_number(n):
                append_numbers.append(s)
            num_list.append(n)
        return(make_numbers(append_numbers,keta-1))

make_numbers(["3","5","7"],keta)

ans = 0
for i in num_list:
    if int(i) <= n and ("3" in i) and ("5" in i) and ("7" in i):
        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 '357') else 0
    for c in '357':
        ret += dfs(s + c)
    return ret

print(dfs('0'))

Solution (Python):
import sys

n = int(input())
sys.setrecursionlimit(2*10**9+1)


def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(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"))

Solution (Python):
def judge(x):
  a=0
  b=0
  c=0
  d=len(x)
  for i in range(d):
    if x[i]=='3':
      a=1
    elif x[i]=='5':
      b=1
    else:
      c=1
      
  if a+b+c==3:
    return True
  else:
    return False

N=int(input())

nums=[['3', '5', '7']]
for i in range(8):
  temp=[]
  lastnums=nums[-1]
  for j in lastnums:
    temp+=[j+'3', j+'5', j+'7']
    
  nums.append(temp)
  
counter=0
nums=nums[2:]
for i in nums:
  for j in i:
    if int(j)<=N and judge(j)==True:
      counter+=1
      
print(counter)

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


def main():
    N = input()[:-1]

    cnt = 0
    for i in range(1, len(N)+1):
        for C in itertools.product(['7','5','3'], repeat=i):
            if ('7' not in C) or ('5' not in C) or ('3' not in C):
                continue
            M = ''.join(C)
            if int(M)<=int(N):
                cnt += 1
    
    print(cnt)
        


if __name__ == '__main__':
    main()

Solution (Python):


N=int(input())

l=[3,5,7]
l_ans=[]
l_ans+=l

if N<357:
    print(0)
else:
    for i in range(8):
        temp=[]
        for item in l:
            temp.append(item+3*10**(i+1))
            temp.append(item+5*10**(i+1))
            temp.append(item+7*10**(i+1))
        l.clear()
        l+=temp
        l_ans+=temp
    l_ans.sort()
    
    count=0
    for i in range(len(l_ans)):
        if l_ans[i]>N:
            break
        elif  ("3" in str(l_ans[i]) and "5" in str(l_ans[i]) and "7" in str(l_ans[i]))==False:
            pass
        else:
            count+=1
            
    print(count)

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

N = int(input())
symbols = list("357")

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

print(dfs("0"))

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

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

print(dfs('0'))

Solution (Python):
n = int(input())
global count
count = 0
def dfs(s):
    if int(s) > n:
        return 0
    if set(list(s[1:])) == {'3','5','7'}:
        global count
        count += 1
    for i in '753':
        dfs(s + i)
dfs('0')
print(count)

Solution (Python):
import itertools
n=int(input())
numbers=0
uselists=[]
for j in itertools.product(["3","5","7"],repeat=len(str(n))):
        s="".join(j)
        uselists.append(s) 

for _ in uselists:
    if int(_)<=n and len(set(_))>=3:
        numbers+=1
        
        
    else:
        continue
        
listss=[0, 0, 0, 6, 36, 150, 540, 1806, 5796, 18150]
for x in range(len(str(n))):
    numbers+=listss[x]
print(numbers)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict
s = input()
L = len(s)
N = int(s)
ls = [3, 5, 7]
dic = defaultdict(int)
def dfs(s):
  if len(s)<L:
    return dfs(s+'3')+dfs(s+'5')+dfs(s+'7')+dfs('0'+s)
  if (not '3' in s) or(not '5' in s) or(not '7' in s):
    return 0
  if int(s)<=N and dic[s]==0:
    dic[s]=1
    return 1
  else:
    return 0
print(dfs(''))

Solution (Python):
import itertools

def test():
    n = input()
    N = int(n)
    ans = 0
    for i in range(1,len(n)+1):
        for j in itertools.product(["3","5","7"],repeat=i):
            s="".join(j)
            v = int(s)
            if "3" in s and "5" in s and "7" in s and v <= N:
                ans += 1
    print(ans)


if __name__ == "__main__":
    test()

Solution (Python):
from itertools import product
N = int(input())
ans = 0
if N <= 2:
  print(0)
  exit()
  
for i in range(3, len(str(N))+1):
  for num in list(product('735',repeat=i)):
    if int(''.join(num)) <= N and '7' in num and '5' in num and '3' in num:
      ans += 1
print(ans)

Solution (Python):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N = INT()

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 sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    def dfs(s):
        if int(s)>n: return 0
        res=int(all(s.count(c)>=1 for c in "753"))
        for c in "753":
            res+=dfs(s+c)
        return res
    print(dfs('0'))
resolve()

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

def dfs(num):
    if int(num) > N:
        return 0
    ret = 1 if all(num.count(c) > 0 for c in '753') else 0

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


print(dfs('0'))

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7



N = int(input())

def dfs(X, bit, count):
    if bit == 7:
        if X <= N:
            count += 1

    if X >= N:
        return count


    count = dfs(X*10+7, bit|4, count)
    count = dfs(X*10+5, bit|2, count)
    count = dfs(X*10+3, bit|1, count)

    return count


count = dfs(0, 0, 0)
print(count)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
okForm = set((3, 5, 7))
memo = dict()


def create(cn, nn):
    if memo.get((cn, nn)) != None:
        return memo[(cn, nn)]
    num = int(str(nn)+str(cn))
    if (num > n):
        return 0
    ans = 1 if set(map(int, list(str(num)))) == okForm else 0
    
    ans += create(num, 3) + create(num, 5) + create(num, 7)
    memo[(cn, nn)] = ans
    return ans


print(create('', 3)+create('', 5)+create('', 7))

Solution (Python):
import itertools as it
import collections as col
import heapq
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N=input()

D=set()
for n in range(1,10):
    for d in it.product(['3','5','7'],repeat=n):
        x=0
        for i in range(n):
            x += (10**i)*int(d[n-i-1])
        if (x <= int(N) and '3' in d and '5' in d and '7' in d):
            D.add(x)

print(len(D))

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

def dfs(x, a, b, c):
    global ans
    if x > N:
        return
    if (a & b & c):
        ans += 1
    dfs(10 * x + 3, 1, b, c)
    dfs(10 * x + 5, a, 1, c)
    dfs(10 * x + 7, a, b, 1)

dfs(0, 0, 0, 0)
print(ans)

Solution (Python):
n = int(input())
def sgs(s):
    if n < int(s):
        return 0
    ret = 1 if all(s.count(i) > 0 for i in '357') else 0
    for i in '357':
        ret += sgs(s + i)
    return ret
print(sgs('0'))

Solution (Python):
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy


sys.setrecursionlimit(10**6)

def check(n,a,b,c,t,l):
    tmp = 0
    if len(n) > l:
        return 0
    if n == "":
        return check(n+"3",a+1,b,c,t,l) + check(n+"5",a,b+1,c,t,l) + check(n+"7",a,b,c+1,t,l) + tmp
    if a and b and c and int(n) <= t:
        tmp = 1
    return check(n+"3",a+1,b,c,t,l) + check(n+"5",a,b+1,c,t,l) + check(n+"7",a,b,c+1,t,l) + tmp

def main():
    N = int(input())
    l = len(str(N))
    print(check("",0,0,0,N,l))

if __name__ == '__main__':
    main()

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


def fn(x):
    global ans
    if int(x) > N:
        return
    if all(x.count(i) for i in '753'):
        ans += 1
    for i in '753':
        fn(x + i)


fn('0')
print(ans)

Solution (Python):
N = input()
L = len(N)

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

for i in range(L):
    pp, dp = dp, pp
    dp = [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
    n = int(N[i])
    dp[0][0][0][1] += pp[0][0][0][1]
    dp[1][0][0][1] += pp[0][0][0][1] + pp[1][0][0][1]
    dp[0][1][0][1] += pp[0][0][0][1] + pp[0][1][0][1]
    dp[0][0][1][1] += pp[0][0][0][1] + pp[0][0][1][1]
    dp[1][1][0][1] += pp[1][0][0][1] + pp[0][1][0][1] + pp[1][1][0][1] * 2
    dp[1][0][1][1] += pp[1][0][0][1] + pp[0][0][1][1] + pp[1][0][1][1] * 2
    dp[0][1][1][1] += pp[0][1][0][1] + pp[0][0][1][1] + pp[0][1][1][1] * 2
    dp[1][1][1][1] += pp[1][1][0][1] + pp[1][0][1][1] + pp[0][1][1][1] + pp[1][1][1][1] * 3
    if n > 0:
        dp[0][0][0][1] += pp[0][0][0][0]
    if n > 3:
        dp[1][0][0][1] += pp[1][0][0][0] + pp[0][0][0][0]
        dp[1][1][0][1] += pp[1][1][0][0] + pp[0][1][0][0]
        dp[1][0][1][1] += pp[1][0][1][0] + pp[0][0][1][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[0][1][1][0]
    if n > 5:
        dp[0][1][0][1] += pp[0][1][0][0] + pp[0][0][0][0]
        dp[1][1][0][1] += pp[1][1][0][0] + pp[1][0][0][0]
        dp[0][1][1][1] += pp[0][1][1][0] + pp[0][0][1][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[1][0][1][0]
    if n > 7:
        dp[0][0][1][1] += pp[0][0][1][0] + pp[0][0][0][0]
        dp[1][0][1][1] += pp[1][0][1][0] + pp[1][0][0][0]
        dp[0][1][1][1] += pp[0][1][1][0] + pp[0][1][0][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[1][1][0][0]
    if n == 0:
        dp[0][0][0][0] += pp[0][0][0][0]
    if n == 3:
        dp[1][0][0][0] += pp[1][0][0][0] + pp[0][0][0][0]
        dp[1][1][0][0] += pp[1][1][0][0] + pp[0][1][0][0]
        dp[1][0][1][0] += pp[1][0][1][0] + pp[0][0][1][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[0][1][1][0]
    if n == 5:
        dp[0][1][0][0] += pp[0][1][0][0] + pp[0][0][0][0]
        dp[1][1][0][0] += pp[1][1][0][0] + pp[1][0][0][0]
        dp[0][1][1][0] += pp[0][1][1][0] + pp[0][0][1][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[1][0][1][0]
    if n == 7:
        dp[0][0][1][0] += pp[0][0][1][0] + pp[0][0][0][0]
        dp[1][0][1][0] += pp[1][0][1][0] + pp[1][0][0][0]
        dp[0][1][1][0] += pp[0][1][1][0] + pp[0][1][0][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[1][1][0][0]


print(sum(dp[1][1][1]))

Solution (Python):
N = input()
L = len(N)

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

for i in range(L):
    pp, dp = dp, pp
    dp = [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
    n = int(N[i])
    dp[0][0][0][1] += pp[0][0][0][1]
    dp[1][0][0][1] += pp[0][0][0][1] + pp[1][0][0][1]
    dp[0][1][0][1] += pp[0][0][0][1] + pp[0][1][0][1]
    dp[0][0][1][1] += pp[0][0][0][1] + pp[0][0][1][1]
    dp[1][1][0][1] += pp[1][0][0][1] + pp[0][1][0][1] + pp[1][1][0][1] * 2
    dp[1][0][1][1] += pp[1][0][0][1] + pp[0][0][1][1] + pp[1][0][1][1] * 2
    dp[0][1][1][1] += pp[0][1][0][1] + pp[0][0][1][1] + pp[0][1][1][1] * 2
    dp[1][1][1][1] += pp[1][1][0][1] + pp[1][0][1][1] + pp[0][1][1][1] + pp[1][1][1][1] * 3
    if n > 0:
        dp[0][0][0][1] += pp[0][0][0][0]
    if n > 3:
        dp[1][0][0][1] += pp[1][0][0][0] + pp[0][0][0][0]
        dp[1][1][0][1] += pp[1][1][0][0] + pp[0][1][0][0]
        dp[1][0][1][1] += pp[1][0][1][0] + pp[0][0][1][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[0][1][1][0]
    if n > 5:
        dp[0][1][0][1] += pp[0][1][0][0] + pp[0][0][0][0]
        dp[1][1][0][1] += pp[1][1][0][0] + pp[1][0][0][0]
        dp[0][1][1][1] += pp[0][1][1][0] + pp[0][0][1][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[1][0][1][0]
    if n > 7:
        dp[0][0][1][1] += pp[0][0][1][0] + pp[0][0][0][0]
        dp[1][0][1][1] += pp[1][0][1][0] + pp[1][0][0][0]
        dp[0][1][1][1] += pp[0][1][1][0] + pp[0][1][0][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[1][1][0][0]
    if n == 0:
        dp[0][0][0][0] += pp[0][0][0][0]
    if n == 3:
        dp[1][0][0][0] += pp[1][0][0][0] + pp[0][0][0][0]
        dp[1][1][0][0] += pp[1][1][0][0] + pp[0][1][0][0]
        dp[1][0][1][0] += pp[1][0][1][0] + pp[0][0][1][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[0][1][1][0]
    if n == 5:
        dp[0][1][0][0] += pp[0][1][0][0] + pp[0][0][0][0]
        dp[1][1][0][0] += pp[1][1][0][0] + pp[1][0][0][0]
        dp[0][1][1][0] += pp[0][1][1][0] + pp[0][0][1][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[1][0][1][0]
    if n == 7:
        dp[0][0][1][0] += pp[0][0][1][0] + pp[0][0][0][0]
        dp[1][0][1][0] += pp[1][0][1][0] + pp[1][0][0][0]
        dp[0][1][1][0] += pp[0][1][1][0] + pp[0][1][0][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[1][1][0][0]


print(sum(dp[1][1][1]))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())


def dfs(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 += dfs(s + 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):
import copy

N=int(input())

tmp0=[]
tmp1=[3,5,7]
res=[3,5,7]
for i in range(1,9):
  for j in tmp1:
    for k in [3,5,7]:
      res.append(j*10+k)
      tmp0.append(j*10+k)
  tmp1=copy.deepcopy(tmp0)
  tmp0=[]

res2=[]
for i in res:
  if len(set(str(i)))==3:
    res2.append(i)


ans=0
for i in res2:
  if i<=N:
    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())
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
  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
  ret = 0
  if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
    ret = 1
  ret += dfs(s+'3') + dfs(s+'5') + dfs(s+'7')
  return ret

print(dfs('0'))

Solution (Python):
N = int(input())
b = []

def seve(a):
    a = int(a)
    if a > N:
        return len(b)
    else:
        a = str(a)
        if a.count('3') >= 1 and a.count('5') >= 1 and a.count('7') >= 1:
            b.append(a)
        return seve(a+'3') + seve(a+'5') + seve(a+'7')

seve('7')
seve('5')
seve('3')
print(len(b))

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

ans = 0
for d in range(1, 11):
    for i in range(3 ** d):
        x = 0
        for j in range(d):
            x += [3, 5, 7][i%3] * 10 ** j
            i = i // 3
        if x > N:
            break
        if len(set(str(x))) == 3:
            ans += 1
print(ans)

Solution (Python):
from itertools import product
import bisect
N=int(input())
A=[]
for n in range(3,len(str(N))+1):
    for s in product([3,5,7], repeat=n):
        if '3' in ''.join(map(str, s)) and '5' in ''.join(map(str, s)) and '7' in ''.join(map(str, s)):
            A.append(int(''.join(map(str, s))))
print(bisect.bisect_right(A,N))

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
    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 sys
sys.setrecursionlimit(10**6)

N=input()
A=[]
def func(d,n,t):
	if d==t:
		return
	for i in [3,5,7]:
		A.append(10*n+i)
		func(d+1, 10*n+i,t)
func(0,0,len(N))


ans=0
for a in A:
	a_str=str(a)
	if '3' in a_str and '5' in a_str and '7' in a_str and a<=int(N):
		ans+=1
print(ans)

Solution (Python):
N = int(input())
def aaa(n):
    if int(n) > N:
        return 0
    ans = 1 if set(str(int(n))) == {'7', '5', '3'} else 0
    for i in '753':
        ans += aaa(n+i)
    return ans
print(aaa('0'))

Solution (Python):
import math
from itertools import product

N = int(input())
if N <= 356:
    print(0)
    exit()
c = 0
for keta in range(3, int(math.log(N, 10)) + 2):
    for t in product("753", repeat=keta):
        if int("".join(t)) <= N and len(set(t)) == 3:
            c += 1
print(c)

Solution (Python):
import math
from itertools import product

N = int(input())
if N <= 356:
    print(0)
    exit()
c = 0
for keta in range(3, int(math.log(N, 10)) + 2):
    for t in product("753", repeat=keta):
        if int("".join(t)) <= N and len(set(t)) == 3:
            c += 1
print(c)

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

count = 0


def dfs(i, s):
    global count
    if i > 10:
        return

    ok = True
    for c in ['3', '5', '7']:
        if c not in s:
            ok = False
    if ok and int(s) <= n:
        count += 1

    for c in ['3', '5', '7']:
        dfs(i + 1, s + c)


dfs(0, '')
print(count)

Solution (Python):
from itertools import product
import math

n = int(input())
ss = []

for i in range(3, 10):
    for per in product('357', repeat=i):
        if '3' in per and '5' in per and '7' in per:
            ss.append(int(''.join(per)))

ss.append(1000000000)
i = 0
while True:
    if ss[i] > n:
        print(i)
        break
    i += 1

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

def f(target):
    for i in '753':
        targetJoin = str(target) + str(i)
        
        if int(targetJoin) > N:
            continue

        if  '7' in targetJoin and '5' in targetJoin and '3' in targetJoin :
            
            flag = True
            if '0' in targetJoin:
                flag = False
            if '1' in targetJoin:
                flag = False
            if '2' in targetJoin:
                flag = False
            if '4' in targetJoin:
                flag = False
            if '6' in targetJoin:
                flag = False
            if '8' in targetJoin:
                flag = False
            if '9' in targetJoin:
                flag = False
            
            if flag :
                global ans
                ans+=1
                
        f(targetJoin)
        
f(3)
f(5)
f(7)
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):
from itertools import*
n=input()
print(sum(sum(2<len(set(a))and int("".join(a))<=int(n)for a in product("357",repeat=l))for l in range(len(n)+1)))

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

N=int(input())

def keta(x):
    a = 0
    while x>0:
        x//=10
        a+=1
    return a

N_keta = keta(N)

ans=0

for i in range(3,N_keta+1):
    for j in range(3**i):
        s=""
        tmp=j
        f0=False
        f1=False
        f2=False
        for k in range(i):
            r=tmp%3
            if r==0:
                f0=True
                s+="7"
            elif r==1:
                f1=True
                s+="5"
            else:
                f2=True
                s+="3"
            tmp//=3
        if f0 and f1 and f2 and N >= int(s):
            ans+=1
print(ans)

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

import math

N=int(input())

def keta(x):
    a = 0
    while x>0:
        x//=10
        a+=1
    return a

N_keta = keta(N)

ans=0
for i in range(3**N_keta):
    s=""
    tmp=i
    f0=False
    f1=False
    f2=False
    for j in range(N_keta):
        r=tmp%3
        if r==0:
            f0=True
            s+="7"
        elif r==1:
            f1=True
            s+="5"
        else:
            f2=True
            s+="3"
        tmp//=3
    if f0 and f1 and f2 and N >= int(s):
        ans+=1

for i in range(3,N_keta):
    for j in range(3**i):
        s=""
        tmp=j
        f0=False
        f1=False
        f2=False
        for k in range(i):
            r=tmp%3
            if r==0:
                f0=True
                s+="7"
            elif r==1:
                f1=True
                s+="5"
            else:
                f2=True
                s+="3"
            tmp//=3
        if f0 and f1 and f2:
            ans+=1
print(ans)

Solution (Python):
N = int(input())
r = 0
for d in range(1, 11):
  for i in range(3**d):
    x = 0
    for j in range(d):
      x += [3, 5, 7][i%3]*10**j
      i = i//3
    if x > N:
      break
    if len(set(str(x))) == 3:
      
      r += 1
print(r)

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

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

def dfs(n):
    if N < int(n):
        return 0

    ansB = True
    for i in '753':
        if n.count(i) == 0:
            ansB = False
            break
    ans = 0
    if ansB:
        ans = 1

    for i in '753':
        ans += dfs(n + i)
    return ans

print(dfs('0'))

Solution (Python):
n = input()
No753 = ['3','5','7']
for i in range(len(n)-1):
    No753_plus = []
    for no753 in No753:
        No753_plus += ['3' + no753]
        No753_plus += ['5' + no753]
        No753_plus += ['7' + no753]
    No753 += No753_plus
No75 = ['5','7']
for i in range(len(n)-1):
    No75_plus = []
    for no75 in No75:
        No75_plus += ['5' + no75]
        No75_plus += ['7' + no75]
    No75 += No75_plus
No53 = ['3','5']
for i in range(len(n)-1):
    No53_plus = []
    for no53 in No53:
        No53_plus += ['3' + no53]
        No53_plus += ['5' + no53]
    No53 += No53_plus
No37 = ['3','7']
for i in range(len(n)-1):
    No37_plus = []
    for no37 in No37:
        No37_plus += ['3' + no37]
        No37_plus += ['7' + no37]
    No37 += No37_plus
No753 = set(No753)-(set(No75)|set(No53)|set(No37))
count = 0
for no753 in No753:
    if int(no753) <= int(n):
        count += 1
print(count)

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

N = int(input())

counter = 0

def func(cur=0, use=0):
    global counter
    if cur > N:
        return None
    if use == 0b111:
        counter += 1
    func(cur * 10 + 7, use | 0b001)
    func(cur * 10 + 5, use | 0b010)
    func(cur * 10 + 3, use | 0b100)

func()
print(counter)

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

nana_go_sans = [{357, 375, 537, 573, 735, 753}]

order = len(str(n))
for i in range(3, order):
    nana_go_san = set()
    nana_go_san.add(int("3" + "5" * (i - 1) + "7"))
    nana_go_san.add(int("3" + "7" * (i - 1) + "5"))
    nana_go_san.add(int("5" + "3" * (i - 1) + "7"))
    nana_go_san.add(int("5" + "7" * (i - 1) + "3"))
    nana_go_san.add(int("7" + "3" * (i - 1) + "5"))
    nana_go_san.add(int("7" + "5" * (i - 1) + "3"))
    for num in nana_go_sans[i - 3]:
        nana_go_san.add(int("3" + str(num)))
        nana_go_san.add(int("5" + str(num)))
        nana_go_san.add(int("7" + str(num)))
        nana_go_san.add(int(str(num) + "3"))
        nana_go_san.add(int(str(num) + "5"))
        nana_go_san.add(int(str(num) + "7"))
    nana_go_sans.append(nana_go_san)

count = 0
for nana_go_san in nana_go_sans:
    for num in nana_go_san:
        if num <= n:
            count += 1

print(count)

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

if __name__ == '__main__':
    N = int(input())
    count = 0
    digits = len(str(N))
    
    for n in range(1, digits+1):

        for t in product('357', repeat=n):
            num = ''.join(t)
            if int(num) <= N:
                if '3' in num and '5' in num and '7' in num:
                    count += 1
    print(count)