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())
L=[3, 5, 7]
 
def dfs(s):
    if s>N:
        return False
 
    str_s = str(s)
    return sum(dfs(s*10 + i) for i in L) + ("7" in str_s and "5" in str_s and "3" in str_s)
 
 
print(dfs(0))

Solution (Python):
n = int(input())
ans = 0
list_N = [["3", "5", "7"]]

for i in range(2, 10):
    d = []
    for a in list_N[-1]:
        for b in ["3", "5", "7"]:
            k = b + a
            if n >= int(k) and "3" in k and "5" in k and "7" in k:
                ans += 1
            d.append(k)
    list_N.append(d)

print(ans)

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


def dfs(current, judge, count):
    if current > N:
        return
    if judge == 0b111:
        count.append(1)

    dfs(current * 10 + 7, judge | 0b100, count)
    dfs(current * 10 + 5, judge | 0b010, count)
    dfs(current * 10 + 3, judge | 0b001, count)


cnt = []
dfs(0, 0, cnt)
print(sum(cnt))

Solution (Python):
from itertools import product

n=int(input())
if n<357:
  print(0)
  exit()
ans=0
for i in range(3,len(str(n))):
  ans+=3**i-3*(2**i)+3

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

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

cand = []
def rec(n):
  if n > 10**9:
    return
  cand.append(n)
  rec(int(str(n) + "3"))
  rec(int(str(n) + "5"))
  rec(int(str(n) + "7"))
rec(3)
rec(5)
rec(7)
ans = 0

def check(c):
  if "3" in str(c) and "5" in str(c) and "7" in str(c):
    return True
  else:
    return False

for c in cand:
  if c <= n and check(c):
    ans += 1
print(ans)

Solution (Python):
def readinput():
    n=int(input())
    return n

def main(n):
    stock=[]
    for _ in range(10):
        stock.append([])

    stock[0].append('')
    for m in range(1,10):
        for i in range(len(stock[m-1])):
            stock[m].append(stock[m-1][i]+'3')
            stock[m].append(stock[m-1][i]+'5')
            stock[m].append(stock[m-1][i]+'7')
    
    count=0
    for m in range(3,10):
        for i in range(len(stock[m])):
            if int(stock[m][i]) <= n and '3' in stock[m][i] and '5' in stock[m][i] and '7' in stock[m][i]:
                count+=1
                
    return count

S=[]
def dfs(s):
    global S
    if len(s)>10:
        return
    S.append(s)
    for c in '753':
        dfs(s+c)
    return

def main2(n):
    global S
    dfs('')
    count=0
    for s in S:
        if s!='' and int(s)>n:
            continue
        if '3' in s and '5' in s and '7' in s:
            count+=1
    return count

if __name__=='__main__':
    n=readinput()
    ans=main2(n)
    print(ans)

Solution (Python):
def readinput():
    n=int(input())
    return n

def main(n):
    stock=[]
    for _ in range(10):
        stock.append([])

    stock[0].append('')
    for m in range(1,10):
        for i in range(len(stock[m-1])):
            stock[m].append(stock[m-1][i]+'3')
            stock[m].append(stock[m-1][i]+'5')
            stock[m].append(stock[m-1][i]+'7')
    
    count=0
    for m in range(3,10):
        for i in range(len(stock[m])):
            if int(stock[m][i]) <= n and '3' in stock[m][i] and '5' in stock[m][i] and '7' in stock[m][i]:
                count+=1
                
    return count

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)

Solution (Python):

from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


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





def LI(): return list(map(int, sys.stdin.buffer.readline().split()))




def I(): return int(sys.stdin.buffer.readline())





def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()




def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')







def IR(n): return [I() for i in range(n)]







def LIR(n): return [LI() for i in range(n)]







def SR(n): return [S() for i in range(n)]







def LSR(n): return [LS() for i in range(n)]







def SRL(n): return [list(S()) for i in range(n)]


n = I()


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


print(dfs("0"))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 9)
N = input()
N_len = len(N)
'''
75333
'''





def dfs(a, depth):
    if depth == N_len:
        if int(a) <= int(N) and a.count('3') > 0 \
                and a.count('5') > 0 and a.count('7') > 0 and str(int(a)).count('0') == 0:
            return 1
        else:
            return 0

    ret1 = dfs(a + '0', depth + 1)
    ret2 = dfs(a + '3', depth + 1)
    ret3 = dfs(a + '5', depth + 1)
    ret4 = dfs(a + '7', depth + 1)
    return ret1 + ret2 + ret3 + ret4


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

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

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

def search(x, use):
    if x > n:
        return
    if use == 0b111:
        cnt.append(1)
        
    search(x * 10 + 3, use | 0b100)
    search(x * 10 + 5, use | 0b010)
    search(x * 10 + 7, use | 0b001)

search(0, 0)
print(sum(cnt))

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

n = int(input())

def search(x, use, cnt):
    if x > n:
        return
    if use == 0b111:
        cnt.append(1)
        
    search(x * 10 + 3, use | 0b100, cnt)
    search(x * 10 + 5, use | 0b010, cnt)
    search(x * 10 + 7, use | 0b001, cnt)

res = []
search(0, 0, res)
print(sum(res))

Solution (Python):
n = int(input())
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

if n < 357:
    print(0)
else:
    ans = 0
    for i in range(3, 10):
        for j in range(3**i):
            a = ''
            val = Base_10_to_n(j, 3).zfill(i)
            for k in val:
                if k == '1':
                    a += '3'
                elif k == '2':
                    a += '5'
                else:
                    a += '7'
            if len(set(a)) == 3 and n >= int(a):
                ans += 1
    print(ans)

Solution (Python):
n = input()
from itertools import product
sum = 0
for i in range(len(n)-2):
  for j in list(product("753", repeat=i+3)):
    if int(''.join(j)) <= int(n) and len(set(j))==3:
      sum+=1
print(sum)

Solution (Python):
N = input()
n = len(N)
ans = 0
if n < 3:
    print(0)
    exit()
if n > 3:
    for i in range(3,n):
        ans += 3**i - 3*(2**i) + 3
a = int(N[0])
if a > 3:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
if a > 5:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
if a > 7:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
b = int(N[1])
c = int(N[2])
if a == 3:
    if b > 3:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b > 5:
        ans += 3**(n-2) - (2**(n-2))
    if b > 7:
        ans += 3**(n-2) - (2**(n-2))
    if b == 3:
        if c > 3:
            ans += 3**(n-3) - 2*(2**(n-3)) + 1
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 5:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3)
    if b == 7:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3)
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
elif a == 5:
    if b > 3:
        ans += 3**(n-2) - (2**(n-2))
    if b > 5:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b > 7:
        ans += 3**(n-2) - (2**(n-2))
    if b == 3:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3)
    if b == 5:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - 2*(2**(n-3)) + 1
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 7:
        if c > 3:
            ans += 3**(n-3)
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
elif a == 7:
    if b > 3:
        ans += 3**(n-2) - (2**(n-2))
    if b > 5:
        ans += 3**(n-2) - (2**(n-2))
    if b > 7:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b == 3:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3)
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 5:
        if c > 3:
            ans += 3**(n-3)
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 7:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - 2*(2**(n-3)) + 1
    
if (a == 3 or a == 5 or a == 7) and (b == 3 or b == 5 or b == 7) and (c == 3 or c == 5 or c == 7):
    d = (a*100 + b * 10 + c) * 10**(n-3)
    e = int(N) + 1
    t = {"3","5","7"}
    for i in range(d,e):
        u = set(str(i))
        if u == t:
            ans += 1
print(ans)

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

Solution (Python):



from collections import deque






def solve(N):
    dq = deque([(3, {3: 1, 5: 0, 7: 0}),
                (5, {3: 0, 5: 1, 7: 0}),
                (7, {3: 0, 5: 0, 7: 1})])
    ans = 0
    while dq:
        num, check = dq.popleft()
        if num > N:
            break
        if sum(check.values()) == 3:
            ans += 1
        for i in (3, 5, 7):
            new_num = num * 10 + i
            if new_num > N:
                break
            new_check = check.copy()
            new_check[i] = 1
            dq.append((new_num, new_check))
    print(ans)


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

Solution (Python):



from collections import deque




def solve(N):
    dq = deque([(3, [1, 0, 0]), (5, [0, 1, 0]), (7, [0, 0, 1])])
    ans = 0
    while dq:
        num, check = dq.popleft()
        if num > N:
            break
        if sum(check) == 3:
            ans += 1
        for i in (3, 5, 7):
            new_num = num * 10 + i
            if new_num > N:
                break
            new_check = check.copy()
            if i == 3:
                new_check[0] = 1
            elif i == 5:
                new_check[1] = 1
            elif i == 7:
                new_check[2] = 1
            dq.append((new_num, new_check))
    print(ans)


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

Solution (Python):
import itertools

def main():
    n = int(input())
    tar_list = []
    cnt = 0
    
    for a in range(3,len(str(n))+1):
        target = list(itertools.product([3, 5, 7], repeat=a))
        
        for tar in target:
            tar_list = list(tar)
            if tar.count(3) > 0 and tar.count(5) > 0 and  tar.count(7):
                
                ans = 0
                i = a-1
                for ii in tar_list:
                    ans += ii*(10**i)
                    
                    i -= 1
                if ans <= n:
                    cnt +=1
        
    print(cnt)
                    
            
            
            
        
               
if __name__ == "__main__":
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    def dfs(n, used):
        if n > N:
            return 0
        ans = 0
        if used == 7:
            ans += 1
        for i, d in enumerate((3, 5, 7)):
            ans += dfs(10 * n + d, used | (1 << i))
        return ans

    print(dfs(0, 0))
    return


if __name__ == '__main__':
    main()

Solution (Python):
import itertools


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

    
    cnt = 0
    for i in range(3, len(str(N)) + 1):
        for j in itertools.product([3, 5, 7], repeat=i):
            p = 0
            for a, b in enumerate(j[::-1]):
                p += b * 10 ** a

            if p > N:
                break

            
            if len(set(j)) == 3:
                cnt += 1

    print(cnt)


main()

Solution (Python):

import sys
from math import factorial


def comb(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)


def perm(n, r):
    return factorial(n) // factorial(r)


def resultSur97(x):
    return x % (10 ** 9 + 7)

def dfs(s,n):
    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, n)
    return ret

if __name__ == '__main__':
    
    
    a = int(input())    

    



    
    print("{}".format(dfs("0", a)))

Solution (Python):
N= int(input())
Nstr = str(N)
Box = ['3','5','7']
Boxi = set(Box)
Box = []
Box2 = set()
for _ in range(10**9):
    B = Boxi.pop()
    if len(B) < len(Nstr) and int(B) <= N:
        Boxi.add('3'+B)
        Boxi.add('5'+B)
        Boxi.add('7'+B)
        Box2.add('3'+B)
        Box2.add('5'+B)
        Box2.add('7'+B)
    if Boxi == set():
      break
for i in Box2:
    Bint = int(i)
    if Bint <= N and '3' in i and '5' in i and '7' in i:
        Box.append(Bint)
print(len(Box))

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

N=intput()
ans=0
for i in range(1,div10(N)+1):
    for x in product('357',repeat=i):
        if x.count('3')*x.count('5')*x.count('7')>0 and int(''.join(x))<=N:
            ans+=1
print(ans)

Solution (Python):
from collections import deque

def dfs(n):
    stack = deque(['3','5','7'])
    ansl = []
    while stack:
        num_s = stack.pop()
        num = int(num_s)
        if num > n: continue
        if '7' in num_s and '5' in num_s and '3' in num_s:
            ansl.append(num)
        stack.append(num_s+'7')
        stack.append(num_s+'5')
        stack.append(num_s+'3')
    return ansl


def main():
    n = int(input())
    ansl = dfs(n)
    print(len(ansl))


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import product

n = int(input())

if n < 357:
    print(0)
    exit()

ans = 0
for i in range(3, len(str(n))):
    ans += 3**i - 3*(2**i) + 3

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

print(ans)

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

ans="0"
cnt=0
l=["3","5","7"]

def dfs(now):
  global cnt

  if n<int(now):
    return now
  now=str(now)
  if 1<=now.count("3") and 1<=now.count("5") and 1<=now.count("7"):
    cnt+=1

  for i in l:
    a=now+i
    dfs(a)
  
  return cnt
print(dfs(ans))

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    def rec(n, used):
        ans = 0
        if used == 7:
            ans += 1
        for i, d in enumerate((3, 7, 5)):
            if 10 * n + d <= N:
                ans += rec(10 * n + d, used | (1 << i))
        return ans

    print(rec(0, 0))
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    def rec(n, used):
        ans = 0
        if all(used):
            ans += 1
        for i, d in enumerate((3, 7, 5)):
            if 10 * n + d <= N:
                cur = used[i]
                used[i] = True
                ans += rec(10 * n + d, used)
                used[i] = cur
        return ans

    print(rec(0, [False, False, False]))
    return


if __name__ == '__main__':
    main()

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

def dfs(cur, use, cnt):
    if cur > n:
        return
    if use == 0b111:
        cnt.append(1)

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

cnt = []
dfs(0, 0, cnt)
print(len(cnt))

Solution (Python):
import itertools

def main():
    N = int(input())
    if N < 100:
        print(0)
        exit()
    ans = 0
    for rep in range(3, len(str(N))+1):
        for comb in itertools.product(["3", "5", "7"], repeat=rep):
            if len(set(comb)) != 3:
                continue
            if int("".join(comb)) <= N:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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

def f(num, use, counter):
    if num >N:
        return
    if use == 0b111:
        counter.append(1)
    f(num*10 + 7, use | 0b001, counter)
    f(num*10 + 5, use | 0b010, counter)
    f(num*10 + 3, use | 0b100, counter)

ans = []
f(0, 0, ans)
print(sum(ans))

Solution (Python):
def f(v, K):
    global cnt
    v += str(K)
    if len(v) == len_ and int(v) <= N:
        if len(set(v)) == 3:
            cnt += 1
        return
    elif len(v) == len_:
        return
    f(v, 7)
    f(v, 5)
    f(v, 3)

N = int(input())
total = [0, 0]
for i in range(3, 10):
    temp = 3**i - (2**i*3 - 3)
    total.append(temp)
len_ = len(str(N))
ans = sum(total[:len_-1])
cnt = 0
f('','')
ans += cnt
print(ans)

Solution (Python):
import sys
import math
import itertools



def input():
    return sys.stdin.readline().rstrip()


def main():
    list = [[3, 5, 7]]
    N=int(input())
    for i in range(9):
        new = []
        for j in list[-1]:
            a = 10 * j
            new.append(a + 3)
            new.append(a + 5)
            new.append(a + 7)
        list.append(new)

    pass
    count =0
    for sub in list:
        for j in sub:
            s =str(j)
            if j>N:
                print(count)
                exit()
            if "3" in s and "7" in s and "5" in s:
                count +=1






if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
import itertools



def input():
    return sys.stdin.readline().rstrip()


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

    A = int(math.log10(N))
    flag=0
    count =0
    for a in range(3,A+2):

        for i in itertools.product([3,5,7],repeat=a):
            digit=0
            if 3 in i and  5 in i and 7 in i:


                for s in range(a):
                    digit+=10**(a-s-1)*i[s]
                if digit <=N:
                    count+=1
                else:
                    break
    print(count)


if __name__ == "__main__":
    main()

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

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

print(dfs('0'))

Solution (Python):
N = int(input())
T = ["3", "5", "7"]
l = T.copy()
ans = 0
while l:
    n = l.pop()
    if int(n) > N:
        continue
    if len(set(n)) == 3:
        ans += 1
    for t in T:
        l.append(n + t)
print(ans)

Solution (Python):
from itertools import product
n_str = input()
n = int(n_str)
e_list = ["3", "5", "7"]
ans = 0
for i in range(3, len(n_str) + 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):
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):
from itertools import product
n_str = input()
n = int(n_str)
ans = 0
for i in range(3, len(n_str) + 1):
    for temp in list(product(["3", "5", "7"], repeat=i)):
        if "3" in temp and "5" in temp and "7" in temp and int("".join(temp)) <= n:
            ans += 1
print(ans)

Solution (Python):
import itertools
N = str(input())
Keta = len(N)
N_List = ["3","5","7"]

Ans = 0
for i in range(3,Keta):
    Ans += 3**i
    Ans -= (2**i*3) -3

N = int(N)

if Keta >= 3:
    for Moji in itertools.product(N_List, repeat=Keta):
        Moji_Kazu = len(set(Moji))
        Str_Number = int("".join(Moji))
        if (Str_Number <= N) & (Moji_Kazu == 3):
            Ans += 1
    
print(Ans)

Solution (Python):
from itertools import product
n_str = input()
n = int(n_str)
ans = 0
for i in range(3, len(n_str) + 1):
    for temp in list(product(["3", "5", "7"], repeat=i)):
        temp_set = set(temp)
        if "3" in temp_set and "5" in temp_set and "7" in temp_set and int("".join(temp)) <= n:
            ans += 1
print(ans)

Solution (Python):
import bisect
def dfs(cnt, s, three, five, seven):
    if cnt == 10:
        return
    if s != "" and min(three, five, seven) > 0:
        v.append(int(s))
    dfs(cnt+1, "3"+s, three+1, five, seven)
    dfs(cnt+1, "5"+s, three, five+1, seven)
    dfs(cnt+1, "7"+s, three, five, seven+1)


v = []
dfs(0, "", 0, 0, 0)
v.sort()

n = int(input())
print(bisect.bisect_right(v, n))

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



def dfs(keta,x):
    if x > N:
        return 0
    if keta == 9:
        three = 0
        five = 0
        seven = 0
        while x:
            if x % 10 == 3:
                three += 1
            elif x % 10 == 5:
                five += 1
            elif x % 10 == 7:
                seven += 1
            else:
                return 0
            x //= 10
        if three > 0 and five > 0 and seven > 0:
            return 1
    else:
        ans = 0
        x *= 10
        ans += dfs(keta+1,x)
        ans += dfs(keta+1,x+3)
        ans += dfs(keta+1,x+5)
        ans += dfs(keta+1,x+7)
        return ans
    return 0

print(dfs(0,0))

Solution (Python):
n = int(input())
ln =len(str(n))

if ln ==10:
    ln =9

res = 0

from collections import Counter
import itertools
seq =("3","5","7")

for i in range(3,ln+1):
    temp = list(itertools.product(seq, repeat = i))
    for j in temp:
        ja = Counter(j)
        if ja["3"] * ja["5"] * ja["7"] >0:
            jj = ''.join(j)
            tempp = int(jj)
            if tempp <= n:
                res +=1

print(res)

Solution (Python):
import itertools
N = int(input())
count = 0
for i in range(3, len(str(N)) + 1):
    for j in itertools.product('753', repeat=i):
        if int(''.join(j)) <= N and '3' in str(j) and '5'in str(j) and '7' in str(j):
            count += 1

print(count)

Solution (Python):
import itertools

n = int(input())

products = []
for i in range(3, len(str(n)) + 1):
    tmp = list(itertools.product(['3', '5', '7'], repeat = i))
    tmp2 = list(map(''.join, tmp))
    tmp3 = list(map(int, tmp2))
    tmp4 = [j for j in tmp3 if j <= n]
    products = products + tmp4

out = 0
for p in products:
    str_p = str(p)
    if ('3' in str_p) and ('5' in str_p) and ('7' in str_p):
        out += 1
print(out)

Solution (Python):
def main():
    N = int(input())
    L = len(str(N))
    cand = []
    def dfs(s,N,cand):
        if s != '' and int(s) > N:
            return
        
        for i in ['3','5','7']:
            tmp = s + i
            if int(tmp) <= N:
                cand.append(tmp)
            dfs(tmp,N,cand)
    
    dfs('',N,cand)
    ans = 0
    for c in cand:
        if c.count('3') >= 1 and c.count('5') >= 1  and c.count('7') >= 1:
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()

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

def iter_p_adic(n):
    from itertools import product
    tmp = [('3','5','7')] * n
    return product(*tmp)
ans = 0
for k in range(3,len(NS)+1):
    for i in iter_p_adic(k):
        ls = list(i)
        if ls.count('3') > 0 and ls.count('5') > 0 and ls.count('7') > 0 and int(''.join(ls)) <= N:
            ans += 1
print(ans)

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

def dfs(x):
  if x != '' and n < int(x):
    return 0
  if set(x) == {'3','5','7'}:
    c = 1
  else:
    c = 0
  for i in '357':
    c += dfs(x+i)
  return c

print(dfs(''))

Solution (Python):
N=int(input())
A=['3','5','7']
i=0
while 1:
    now=A[i]
    if int(now+'3')<=N:A.append(now+'3')
    if int(now+'5')<=N:A.append(now+'5')
    if int(now+'7')<=N:A.append(now+'7')
    else:break
    i+=1

ans=0
B={'3','5','7'}
for a in A:
    if set(list(a))&B==B:
        ans+=1
print(ans)

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


def conv3570(p):
  D = [0, 3, 5, 7]
  ans = 0
  i = 0
  while p > 0:
    ans += D[p % 4] * 10**i
    p //= 4
    i += 1
  return ans

p = 0
q = 0
ans = 0
while q <= N:
  q_str = str(q)
  if q_str.count("0") == 0 and q_str.count("3") > 0 and q_str.count("5") > 0 and q_str.count("7") > 0:
    ans += 1
  p += 1
  q = conv3570(p)
  
print(ans)

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    N = i_input()
    k = len(str(N))
    ans = 0
    l = []
    def rec(n,k):
        k += 1
        if int(n) > N:
            return
        if "3" in n and "5" in n and "7" in n:
            l.append(int(n))
        rec(n+"3",k)
        rec(n+"5",k)
        rec(n+"7",k)
    rec("0",0)
    print(len(l))





if __name__=="__main__":
    main()

Solution (Python):
N = int(input())
T = ("3","5","7")

def dfs(x):
  if x != "" and int(x) > N:
    return 0
  res = 0
  if len(set(x)) == 3:
    res = 1
  for t in T:
    res += dfs(x + t)
  return res
  
print(dfs(""))

Solution (Python):
N = int(input())
T = ("3","5","7")

from collections import deque
que = deque(list(T))

ans = 0
while que:
  num = que.pop()
  if int(num) > N:
    continue
  if len(set(num)) == 3:
    ans += 1
  for t in T:
    que.append(num + t)

print(ans)

Solution (Python):
N = int(input())
T = ("3","5","7")

from collections import deque
que = deque(list(T))

ans = 0
while que:
  num = que.popleft()
  if int(num) > N:
    continue
  if len(set(num)) == 3:
    ans += 1
  for t in T:
    que.append(num + t)

print(ans)

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

N = int(N)

import itertools

ans = 0
for i in range(1, digit + 1):
  for prod in itertools.product(("3","5","7"), repeat = i):
    if int("".join(prod)) <= N and len(set(prod)) == 3:
      ans += 1

print(ans)

Solution (Python):
N=int(input())
s=len(str(N))

ans=0
import itertools
b1=list(itertools.product("0357", repeat=s))
for k in b1:
    t=int(''.join(k))
    if N<t:break
    x=set(str(t))
    y=x-{'3','5','7'}
    if len(y)==0 and len(x-y)==3:
        ans+=1
print(ans)

Solution (Python):

n=int(input())
def dfs(s):
    if int(s)>n:
        return 0
    cnt=0
    if all(i in s for   i in "357"):
        cnt=1
    for i in "357":
        cnt+= dfs(s+i)
    return cnt 
print(dfs("0"))

Solution (Python):
from collections import deque
N = int(input())
S = deque([3, 5, 7])
ans = 0
for _ in range(3**10):
    a = S.popleft()
    if a <= N:
        tmp = a
        j3, j5, j7 = False, False, False
        while tmp > 0:
            if tmp%10 == 3:
                j3 = True
            elif tmp%10 == 5:
                j5 = True
            else:
                j7 = True
            tmp //= 10
        if j3 and j5 and j7:
            ans += 1
    S.append(a*10+3)
    S.append(a*10+5)
    S.append(a*10+7)
print(ans)