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):
from itertools import product
def main():
    def is_753(s):
        return '7' in s and '5' in s and '3' in s

    S = input()
    N = int(S)
    r = 0
    for i in range(len(S)):
        for j in product('753', repeat=i + 1):
            t = ''.join(j)
            if int(t) <= N and is_753(t):
                r += 1
    return r
print(main())

Solution (Python):
def dfs(s, n):
    if int(s) > n:
        return 0
    cnt = 0
    if "7" in s and "5" in s and "3" in s:
        cnt += 1
    return cnt + dfs(s + "7", n) + dfs(s + "5", n) + dfs(s + "3", n)

n = int(input())
print((dfs("0", 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):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18


N = I()
def dfs(s, n):
    if int(s) > n:
        return 0
    count = 0
    if '7' in s and '5' in s and '3' in s:
        count += 1
    return count + dfs(s+'7', n) + dfs(s+'5', n) + dfs(s+'3', n)
print(dfs('0', N))

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

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

    ans = 1 if all(x.count(c)  for c in "753") > 0 else 0

    for n in "753":
        ans += dfs(x+n)

    return ans


print(dfs("0"))

Solution (Python):
s = input()
l = len(s)
n = int(s)
ans = 0
import itertools
for li in range(3, l+1):
    for i in itertools.product([7, 5, 3], repeat=li):
        if len(set(i)) != 3:
            continue
        num = int(''.join(map(str, i)))
        if num <= n:
            ans += 1

print(ans)

Solution (Python):
s = input()
l = len(s)
n = int(s)
ans = 0
import itertools
for li in range(3, l+1):
    for i in itertools.product([7, 5, 3], repeat=li):
        num = int(''.join(map(str, i)))
        if num > n:
            continue
        if len(set(i)) == 3:
            ans += 1
print(ans)

Solution (Python):


n = int(input())

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

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

Solution (Python):
n = int(input())
count = 0
def dfs(x):
    global count
    if x <= n and len(set(str(x)))==3:
        count += 1

    x *= 10
    for i in [3, 5, 7]:
        if x > n: continue
        x += i
        dfs(x)
        x -= i
dfs(0)
print(count)

Solution (Python):
import math
def main():
    n=int(input())
    if n<357:
        print(0)
    else:
        numRange=math.ceil(math.log10(n))
        num=[0]*numRange
        num[0:3]=[0,1,1]
        check=0
        ans=0
        for i in range((3**(numRange+1)-1)//2-13):
            num[0]+=1
            j=0
            while j<numRange-1 and num[j]==4:
                num[j+1]+=1
                num[j]=1
                j+=1
            if 1 in num and 2 in num and 3 in num:
                j=0
                check=0
                while j<numRange and num[j]!=0:
                    a=0
                    if num[j]==1:
                        a=3
                    elif num[j]==2:
                        a=5
                    else:
                        a=7
                    check+=a*10**j
                    j+=1
                if check<=n:
                    ans+=1
                else:
                    break
        print(ans)
if __name__=="__main__":
    main()

Solution (Python):
import itertools

n = int(input())
count = 0
for i in range(3,10):
    li = list(itertools.product(range(3), repeat=i))
    
    for l in li:
        st = ''
        for ll in l:
            if ll == 0:
                st += '3'
            elif ll == 1:
                st += '5'
            else:
                st += '7'
        if len(set(list(st))) == 3 and int(st)<=n:
            count += 1
print(count)

Solution (Python):
s = input()
n = int(s)
l = len(s)

dp = [[] for _ in range(l+1)]
dp[0].append('')

for i in range(l):
  for e in dp[i]:
    dp[i+1].append(e+'3')
    dp[i+1].append(e+'5')
    dp[i+1].append(e+'7')
ans = 0

for i in range(min(3,l+1),l+1):
  for e in dp[i]:
    if '3' in e and '5' in e and '7' in e and int(e) <= n:
      ans += 1
      
print(ans)

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

def f(x):
    if int(x) > N:
        return 0
    else:
        if all(x.count(j) >= 1 for j in ["3", "5", "7"]):
            ans = 1
        else:
            ans = 0
        for i in ["3", "5", "7"]:
            ans += f(x+i)    
        return ans        

print(f("0"))

Solution (Python):
def generator(n=9):
    if n == 0:
        yield 0
    else:
        for a in generator(n - 1):
            for i in (0, 3, 5, 7):
                yield 10 * a + i


n = int(input())
cnt = 0
for a in generator():
    if a > n:
        break
    if set(str(a)) == {'3', '5', '7'}:
        cnt += 1
print(cnt)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
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
def main():
    global n
    n=int(input())
    print(dfs('0'))

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
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
def main():
    global n
    n=int(input())
    print(dfs('0'))

if __name__=='__main__':
    main()

Solution (Python):

import sys



def solve(N: int):
    from itertools import product, count, takewhile
    ans = 0
    for i in range(10):
        for s in product('357', repeat=i):
            if any(c not in s for c in '357'):
                continue
            if int(''.join(s)) <= N:
                ans += 1
    return 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))  
    print(solve(N))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):

import sys



def solve(N: int):
    from itertools import product, count, takewhile
    ans = 0
    for i in range(10):
        for s in product('357', repeat=i):
            if not('3' in s and '5' in s and '7' in s):
                continue
            if int(''.join(s)) <= N:
                ans += 1
    return 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))  
    print(solve(N))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
cnt = 0
q = ['3', '5', '7']
while q:
    qq = q.pop()
    v = list(qq)
    if '3' in v and '5' in v and '7' in v:
        cnt += 1
    if int(qq + '3') <= n:
        q.append(qq + '3')
        if int(qq + '5') <= n:
            q.append(qq + '5')
            if int(qq + '7') <= n:
                q.append(qq + '7')
print(cnt)

Solution (Python):
n=int(input())
def dfs(tmp,num):
    if tmp > n:
        return
    if num == 0b111:
        cnt[0]+=1
    dfs(tmp*10+7, num | 0b001)
    dfs(tmp*10+5,num | 0b010)
    dfs(tmp*10+3,num | 0b100)
    
cnt=[0]
dfs(0,0)
print(cnt[0])

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

N = int(input())
cnt = [0]
dfs(0, 0)
print(cnt[0])

Solution (Python):


import sys












from itertools import product, permutations  









def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    digit = len(str(n))
    ans = 0
    for i in range(3, digit):
        
        p = product([3, 5, 7], repeat=i)
        for l in p:
            if len(list(set(l))) == 3:
                ans += 1
    
    p = product([3, 5, 7], repeat=digit)
    for l in p:
        if len(list(set(l))) == 3 and int(''.join(map(str, l))) <= n:
            ans += 1
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
import itertools


def main():
    N = int(input())
    L = len(str(N))
    cnt = 0
    for length in range(3, L + 1):
        for semi_753 in itertools.product(['3', '5', '7'], repeat=length):
            n_str = ''.join(semi_753)
            if '3' in n_str and '5' in n_str and '7' in n_str:
                n = int(n_str)
                if n <= N:
                    cnt += 1
    print(cnt)


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)


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

Solution (Python):
import itertools
N = int(input())
ans = 0
for i in range(3, 10):
    product = list(itertools.product(['3', '5', '7'], repeat=i))
    for li in product:
        if len(set(li)) == 3:
            if int(''.join(li)) <= N:
                ans += 1
print(ans)

Solution (Python):
import itertools
N = int(input())
ans = 0
for i in range(3, 10):
    product = list(itertools.product(['3', '5', '7'], repeat=i))
    for li in product:
        if len(set(li)) == 3:
            if int(''.join(li)) <= N:
                ans += 1
print(ans)

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

d=['3','5','7','']
k=10
a=d
def make(k,l):
    if k==0:
        return l
    t=set()
    for i in l:
        for j in d:
            t.add(i+j)
    return make(k-1,t)

s=[]    
for i in make(k,d):
    if i!='':
        u=set()
        for j in i:
            u.add(j)
        if len(u)==3:
            s.append(int(i))

ans=sum([1 if x<=n else 0 for x in s])
print(ans)

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

readline = stdin.buffer.readline

INF = 10 ** 10

N = int(readline())

cnt = 0

def dfs(A):
    global cnt
    if int(''.join(A)) > N:
        return
    
    if len(set(A)) == 4:
        cnt += 1
    
    
    for i in ["3", "5", "7"]:
        A.append(i)
        dfs(A)
        A.pop()


dfs(["0"])

print(cnt)

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

readline = stdin.buffer.readline

INF = 10 ** 10

N = int(readline())

cnt = 0

def dfs(A):
    global cnt
    if int(''.join(A)) > N:
        return
    
    if "3" in A and "5" in A and "7" in A:
        cnt += 1
    
    
    for i in ["3", "5", "7"]:
        A.append(i)
        dfs(A)
        A.pop()


dfs(["0"])

print(cnt)

Solution (Python):
import itertools
import math


def main():
  n = int(input())
  
  count_753 = 0
  max_digits = int(math.log10(n)) + 2
  cand_753 = ("3", "5", "7")
  
  for digits in range(3, max_digits):
    for dig_753 in itertools.product(cand_753, repeat=digits):
      number_str = "".join(dig_753)
      
      if "7" in number_str and "5" in number_str and "3" in number_str and int(number_str) <= n:
        count_753 += 1
  
  print(count_753)

if __name__ == "__main__":
  main()

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

N = int(readline())

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


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

if __name__ == '__main__':
    main()

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

def main():
    N = int(readline())
    que = []
    for val in ['357', '375', '537', '573', '735', '753']:
        if int(val) <= N:
            que.append(val)
    res = set(que)
    que = deque(que)
    while que:
        pre = que.popleft()
        for p in ['3', '5', '7']:
            for i in range(len(pre)+1):
                next = pre[:i] + p + pre[i:]
                if int(next) <= N and next not in res:
                    que.append(next)
                    res.add(next)

    print(len(res))

if __name__ == '__main__':
    main()

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

def dfs(x):
    if int(x)>n:
        return 0
    ans = [0,1][all(x.count(i) for i in "753")]
    for i in "753":
        ans += dfs(x+i)
    return ans
print(dfs("0"))

Solution (Python):
n = int(input())
from collections import deque
d = deque([0])
cnt = 0
while d[-1] <= n:
    x = d.popleft()
    for i in range(3,8,2):
        d.append(x * 10 + i)
        cnt += 1 if all(str(x * 10 + i).count(c)>0 for c in "753") else 0
ans=0
if d[-3] > n:
    for i in range(1,4):
        ans += 1 if all(str(d[-i]).count(c) > 0 for c in "753") else 0
    print(cnt - ans)
elif d[-2] > n:
    for i in range(1,2):
        ans += 1 if all(str(d[-i]).count(c) > 0 for c in "753") else 0
    print(cnt - ans)
elif d[-1] > n:
    if all (str(d[-1]).count(c) > 0 for c in "753"):
        print(cnt - 1)
    else:
        print(cnt)

Solution (Python):
from itertools import product
n = int(input())
product_list = []
for i in range(3, len(str(n))+1):
    product_list += list(product("753", repeat=i))  

count = 0
for item in product_list:
    if "3" not in item:
        continue
    if "5" not in item:
        continue
    if "7" not in item:
        continue
    item_int = int("".join(item))
    if item_int <= n:
        count += 1
print(count)

Solution (Python):
import sys 
sys.setrecursionlimit(1000000)

def dfs(A, i):
    if i > N:
        return A
    if len(str(i)) >= 3:
        if "3" in str(i) and "5" in str(i) and "7" in str(i):
            A.append(i) 
    for v in range(3, 8 , 2):
        i = i * 10 + v
        dfs(A, i)
        i = int(str(i)[:len(str(i))-1])

N = int(input())
B = []
for i in range(3, 8, 2):
    A = []
    dfs(A, i)
    B = B + A
print(len(B))

Solution (Python):
from collections import deque
n = int(input())
cnt = 0
num_lst = [3, 5, 7]
stack = deque([3, 5, 7])
while len(stack) > 0:
    now_num = stack.popleft()
    if now_num > n:
        break
    if len(set(str(now_num))) == 3:
        cnt += 1
    for x in num_lst:
        next_num = str(now_num) + str(x)
        next_num = int(next_num)
        stack.append(next_num)

print(cnt)

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
def dfs(v):
    global ans
    if v > N: return 0
    if len(set(str(v))) == 3: ans += 1
    for i in (3,5,7):
        dfs(v*10+i)
dfs(0)
print(ans)

Solution (Python):
N = input()
D = len(N)
N = int(N)
ans = 0
def dfs(v):
    global ans
    if v > N: return 0
    if len(set(str(v))) == 3: ans += 1
    for i in (3,5,7):
        dfs(v*10+i)

dfs(0)
print(ans)

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = iss()
    S = []
    for i in range(1, 10):
        S += set(itertools.product('753', repeat=i))
    ret = 0
    for s in S:
        if '7' in s and '5' in s and '3' in s and int(N) >= int("".join(s)):
            ret += 1
    print(ret)


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):
import sys
from collections import deque

input = sys.stdin.readline


def dfs(N):
    stack = deque(["3", "5", "7"])
    num = 0
    while stack:
        n = stack.pop()
        if int(n) > N:
            continue
        num += 1 if all(s in n for s in "357") else 0
        stack.append("3" + n)
        stack.append("5" + n)
        stack.append("7" + n)
    return num


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

    ans = dfs(N)

    print(ans)


if __name__ == "__main__":
    main()

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

def func(cur, use, counter):
  if cur > N: return
  if use == 0b111: counter.append(1)  
    
  
  func(cur * 10 + 7, use | 0b001, counter)
  
  func(cur * 10 + 5, use | 0b010, counter)
  
  func(cur * 10 + 3, use | 0b100, counter)
  
res = []
func(0, 0, res)
print(sum(res))

Solution (Python):
import numpy as np


def enum_753_number():
    enum_array = [3, 5, 7]
    enum_array = enum_753_number_(enum_array, 1)
    return enum_array


def enum_753_number_(enum_array, now_digit):
    now_digit += 1;
    if (now_digit > 9):
        return enum_array
    else:
        enum_3_array = [10*num + 3 for num in enum_array]
        enum_5_array = [10*num + 5 for num in enum_array]
        enum_7_array = [10*num + 7 for num in enum_array]
        enum_array.extend(enum_753_number_(enum_3_array, now_digit))
        enum_array.extend(enum_753_number_(enum_5_array, now_digit))
        enum_array.extend(enum_753_number_(enum_7_array, now_digit))
        return enum_array


def check_753_number(number):
    flag_3 = False
    flag_5 = False
    flag_7 = False
    if (number < 100):
        return False
    while (number > 1):
        if (number % 10 == 3): flag_3 = True
        if (number % 10 == 5): flag_5 = True
        if (number % 10 == 7): flag_7 = True
        number = int(number / 10)
    if (flag_3 == True and flag_5 == True and flag_7 == True):
        return True
    else:
        return False


def main():
    string = input()
    N = int(string)
    count = 0
    enum_array = enum_753_number()
    for elem in enum_array:
        if (elem <= N and check_753_number(elem)): count+=1
    print(count)


if __name__ == '__main__':
    main()

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

def dfs(cur,use,counter):
    if cur>N:
        return 0
    
    counter=int(use==0b111)

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

    return counter

print(dfs(0,0,0))

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

if len(n) < 3 or int(n) <= 356:
  pass
else:
  num = "753"
  for x in range(3,len(n)+1):
    for y in itertools.product(num, repeat=x):
      if "7" in y and "5" in y and "3" in y:
        if int("".join(y)) <= int(n):
          ans += 1
print(ans)

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

kz_ls = []
q_ls = ['3', '5', '7']
while True:
    if not q_ls:
        break
    else:
        tmp = q_ls.pop(0)
        kz_ls.append(tmp)
        if len(tmp) < 9:
            q_ls.append(tmp + '3')
            q_ls.append(tmp + '5')
            q_ls.append(tmp + '7')

kazus = []
for item in kz_ls:
    if item.count('3') > 0 and item.count('5') > 0 and item.count('7') > 0:
        kazus.append(int(item))

kazus.sort()

ret = 0
for item in kazus:
    if item <= n:
        ret += 1
print(ret)

Solution (Python):
from itertools import product

n = int(input())

digit = len(str(n))

cnt = 0
for d in range(3, digit+1):
    gen = product(["7", "5", "3"], repeat=d)
    for gen_num in gen:
        s = "".join(gen_num)
        if "7" not in s:
            continue
        if "5" not in s:
            continue
        if "3" not in s:
            continue
        if int(s) > n:
            continue
        cnt += 1
print(cnt)

Solution (Python):
import itertools
n = input()
number = list("753")
N = []
flag = False
for i in range(3, 10):
  for v in itertools.product(number, repeat=i):
    if "7" in v and "5" in v and "3" in v:
      if int("".join(v)) <= int(n): N.append(int("".join(v)))
print(len(N))

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

bit = 0
n_sub = n
while n_sub > 0:
  bit += 1
  n_sub //= 10

index = 0
key = [(3, 1), (5, 2), (7, 3)]

for i in range(1, bit):
  last = len(key)
  for j in range(index, last):
    k1, k2 = key[j][0], key[j][1]
    if k2 == 1:
      key.append((k1*10+3, 1))
      key.append((k1*10+5, 4))
      key.append((k1*10+7, 5))
    if k2 == 2:
      key.append((k1*10+3, 4))
      key.append((k1*10+5, 2))
      key.append((k1*10+7, 6))
    if k2 == 3:
      key.append((k1*10+3, 5))
      key.append((k1*10+5, 6))
      key.append((k1*10+7, 3))
    if k2 == 4:
      key.append((k1*10+3, 4))
      key.append((k1*10+5, 4))
      key.append((k1*10+7, 7))
    if k2 == 5:
      key.append((k1*10+3, 5))
      key.append((k1*10+5, 7))
      key.append((k1*10+7, 5))
    if k2 == 6:
      key.append((k1*10+3, 7))
      key.append((k1*10+5, 6))
      key.append((k1*10+7, 6))
    if k2 == 7:
      key.append((k1*10+3, 7))
      key.append((k1*10+5, 7))
      key.append((k1*10+7, 7))
  index = last

ans = 0
for value in key:
  v1, v2 = value[0], value[1]
  if v2 == 7 and v1 <= 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(f) for f in "753") else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))

Solution (Python):


from collections import deque


N = input()
n_keta = len(N)
N = int(N)


class Search:
    def __init__(self, n, keta):
        self.ans = 0
        self.n = n
        self.keta = keta

    def get_ans(self):
        return self.ans

    def check_str(self, check_num, check_str):
        return check_num<=self.n and '3' in check_str and '5' in check_str and '7' in check_str

    
    
    def dfs(self, num_str):
        if len(num_str)==self.keta:
            check_num = int("".join(num_str))
            if self.check_str(check_num, num_str):
                self.ans += 1
        else:
            for s in ['3', '5', '7']:
                num_str.append(s)
                check_num = int("".join(num_str))
                if len(num_str)<self.keta:
                    if self.check_str(check_num, num_str):
                        self.ans += 1
                self.dfs(num_str)
                num_str.pop()


dfs_search = Search(N, n_keta)
num_str = deque([])
dfs_search.dfs(num_str)


print(dfs_search.get_ans())

Solution (Python):

counter = 0
N = 0
def dfs(cur,use):
    global counter,N
    if(cur > N): return
    if(use == 7): counter += 1

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


def main():
    global N
    N = int(input())
    dfs(0,0)
    print(counter)

if __name__ == "__main__":
    main()

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

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

res=0
func(0,0)
print(res)

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

def dfs(val, A):
	if val > n:
		return

	A.append(val)

	for v in [3, 5, 7]:
		dfs(10 * val + v, A)


A = []
for v in [3, 5, 7]:
	dfs(v, A)

cnt = 0
for v in A:
	if '3' in str(v) and '5' in str(v) and '7' in str(v):
		cnt += 1

print(cnt)

Solution (Python):
from itertools import product
n = int(input())
A = set()
for x in product('753_', repeat=9):
    s = ''.join(x).replace('_', '')
    if all(d in s for d in '753') and int(s) <= n:
        A.add(s)
print(len(A))

Solution (Python):
from itertools import product
n = int(input())
A = set()
for x in product('753_', repeat=9):
    s = ''.join(x)
    s = s.replace('_', '')
    if '7' in s and '5' in s and '3' in s and int(s) <= n:
        A.add(s)
print(len(A))

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

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

n = int(input())
ans = []
dfs(0, 0, ans)
print(len(ans))

Solution (Python):
import numpy as np
def enum753():
    table = str.maketrans({
        '0': '3',
        '1': '5',
        '2': '7'
    })
    ret = []
    for d in range(3, 10):
        for n in range(3 ** d):
            s = np.base_repr(n, 3).zfill(d).translate(table)
            if all(c in s for c in "357"):
                ret.append(int(s))
    return ret

print(np.searchsorted(enum753(), int(input()), side="right"))

Solution (Python):
n=int(input())
A=["3","5","7"]
A=set(A)
cnt=0

for _ in range(len(str(n))-1):
	for a in list(A):
		x=a+"3"
		y=a+"5"
		z=a+"7"
		if int(x)<=n:
			A.add(x)
		if int(y)<=n:
			A.add(y)
		if int(z)<=n:
			A.add(z)

res=0

for a in list(A):
	if "3" in a and "5" in a and "7" in a:
		res+=1		

print(res)

Solution (Python):
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)
	
n=int(input())
l=len(str(n))

res=0

for i in range(4**l):
	x=Base_10_to_n(i,4)
	cnt=0
	if not "0" in x: 
		if ("3" in x) and ("2" in x) and ("1" in x):
			for j in range(len(x)):
				if x[j]=="1":
					cnt+=3*(10**j)
				elif x[j]=="2":
					cnt+=5*(10**j)
				elif x[j]=="3":
					cnt+=7*(10**j)
			if cnt<=n:
				res+=1
			
print(res)

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

def dfs(a):
    if int(a) > n:
        return 0
    ret = 1 if all(a.count(c) > 0 for c in '753') else 0
    for v in '753':
        a += v
        ret += dfs(a)  
        a = a[:-1]  
    return ret


print(dfs('0'))

Solution (Python):
n=int(input())
from collections import deque
kouho=["3","5","7"]
d=deque()
d.extend(kouho)
res=0
kk=0
while kk<=n:
  k=d.popleft()
  for x in kouho:
    a=k
    d.append(k+x)
  if not "3" in k:
    continue
  elif not "5" in k:
    continue
  elif not "7" in k:
    continue
  kk=int(k)
  if kk<=n:
    res+=1
  
  
print(res)

Solution (Python):
n=int(input())
import itertools as it
res=0
count=3
oo=""
while count<10:
  lis=list(it.product("375",repeat=count))
  for i in range(0,len(lis)):
    hahaha=lis[i]
    if not "3" in hahaha:
      continue
    elif not "5" in hahaha:
      continue
    elif not "7" in hahaha:
      continue
    hahaha=oo.join(hahaha)
    if int(hahaha)<=n:
      res+=1
  count+=1
print(res)

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

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

ans = 0
for i in range(3, m+1):
    candidates = []
    for v in product(['3', '5', '7'], repeat=i):
        if '3' in v and '5' in v and '7' in v:
            candidates.append(int(''.join(v)))
    candidates.sort()
    ans += bisect_right(candidates, n)

print(ans)

Solution (Python):
import itertools

N = int(input())
digit = 3
ans = 0
while True:
    for t in itertools.product((3, 5, 7), repeat=digit):
        if set(t) != {3, 5, 7}:
            continue
        x = int(''.join(map(str, t)))
        if x > N:
            print(ans)
            exit()
        ans += 1
    digit += 1

Solution (Python):
N=int(input())
M=str(N)
L=len(M)
A=[[] for _ in range(L+1)]
A[0]=[""]

cnt=0
for i in range(1,L+1):
  for a in A[i-1]:
    b = a+"3"
    c=  a+"5"
    d=  a+"7"
    if int(b) <= N:
      A[i].append(b)
    if int(c) <= N:
      A[i].append(c)
    if int(d) <= N:
      A[i].append(d)
  for item in A[i]:
    if item.count("3")>=1 and item.count("5")>=1 and item.count("7")>=1:
      cnt+=1
print(cnt)

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())
ret = 0
def func(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 += func(s+c)
    return ret
    
print(func('0'))

Solution (Python):
from collections import deque

n=int(input())
num=["3","5","7"]
a=deque([])
ans=0

def dfs():
  global ans
  if len(a)>0 and int("".join(a))>n:
    return
  if "3" in a and "5" in a and "7" in a:
    ans+=1
  for i in num:
    a.append(i)
    
    dfs()
    a.pop()
dfs()
print(ans)

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

def dfs(value, use):
    if int(value) > N:
        return 0

    res = int(use == 0b111)
    res += dfs(value + "7", use | 0b001)
    res += dfs(value + "5", use | 0b010)
    res += dfs(value + "3", use | 0b100)

    return res

print(dfs("0", 0))

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

def dfs(value, use):
    if value > N:
        return 0

    res = int(use == 0b111)
    res += dfs(value * 10 + 7, use | 0b001)
    res += dfs(value * 10 + 5, use | 0b010)
    res += dfs(value * 10 + 3, use | 0b100)

    return res

print(dfs(0, 0))