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):
def f(n, k):
  num_bit = 3 - bin(k).count('1')
  c = [0, 0, 1, 3]
  return 3**n - num_bit*2**n + c[num_bit]


def solve(N, k=0):
  n = len(N)
  num_used = bin(k).count('1')
  if n==0 and num_used==3:
    return 1
  elif n==0 or n+num_used<3:
    return 0
  else:
    a = int(N[0])
    if a > 7:
      return f(n-1, k|1) + f(n-1, k|2) + f(n-1, k|4)
    elif a == 7:
      return f(n-1, k|2) + f(n-1, k|1) + solve(N[1:], k|4)
    elif a > 5:
      return f(n-1, k|2) + f(n-1, k|1)
    elif a == 5:
      return f(n-1, k|1) + solve(N[1:], k|2)
    elif a > 3:
      return f(n-1, k|1)
    elif a == 3:
      return solve(N[1:], k|1)
    else:
      return 0

N = input()
base = sum([f(i, 0) for i in range(3, len(N))])
print(solve(N) + base)

Solution (Python):


N = int(input().strip())


class Recursion():
    def __init__(self, N :int):
        self.N = N
        self.all_pattern=[]
        
        self.check("")
        
    def check(self, num_str :str):
        for word in "753":
            next_num = num_str + word
            if int(next_num) > self.N:
                continue
            else:
                if all(s in next_num for s in "753"):
                    self.all_pattern.append(next_num)
                self.check(next_num)
        

rec = Recursion(N)
print(len(rec.all_pattern))

Solution (Python):

def add_digit(n, d, x):
    """
    nのd桁目にxを挿入する
    357, 1 -> 357x
    357, 2 -> 35x7
    357, 3 -> 3x57
    357, 4 -> x357
    """
    d1 = (10**(d - 1))
    r = n % d1
    h = n // d1
    return h * d1 * 10 + x * d1 + r


def submit():
    n = int(input())
    satisfied = {357, 375, 537, 573, 735, 753}

    stop = False
    curr_d = 3
    ans = 0
    while True:
        for s in satisfied:
            if s <= n:
                ans += 1
            else:
                stop = True
        
        if stop:
            break

        new_satisfied = []
        for s in satisfied:
            for i in range(1, curr_d + 2):
                new_satisfied.append(add_digit(s, i, 3))
                new_satisfied.append(add_digit(s, i, 5))
                new_satisfied.append(add_digit(s, i, 7))
        satisfied = set(new_satisfied)
        curr_d += 1

    print(ans)


if __name__ == "__main__":
    submit()

Solution (Python):

def add_digit(n, d, x):
    """
    nのd桁目にxを挿入する
    357, 1 -> 357x
    357, 2 -> 35x7
    357, 3 -> 3x57
    357, 4 -> x357
    """
    d1 = (10**(d - 1))
    r = n % d1
    h = n // d1
    return h * d1 * 10 + x * d1 + r


def submit():
    n = int(input())
    satisfied = {357, 375, 537, 573, 735, 753}

    stop = False
    curr_d = 3
    ans = 0
    while True:
        for s in satisfied:
            if s <= n:
                ans += 1
            else:
                stop = True
        
        if stop:
            break

        new_satisfied = []
        for s in satisfied:
            for i in range(1, curr_d + 2):
                new_satisfied.append(add_digit(s, i, 3))
                new_satisfied.append(add_digit(s, i, 5))
                new_satisfied.append(add_digit(s, i, 7))
        satisfied = set(new_satisfied)

    print(ans)


if __name__ == "__main__":
    submit()

Solution (Python):
import itertools as itr

num = int(input())

a = ['0', '3', '5', '7']
b = ['0', '3', '5', '7']
c = ['0', '3', '5', '7']
d = ['0', '3', '5', '7']
e = ['0', '3', '5', '7']
f = ['0', '3', '5', '7']
g = ['0', '3', '5', '7']
h = ['0', '3', '5', '7']
i = ['0', '3', '5', '7']

cnt = 0
for j,k,l,m,n,o,p,q,r in itr.product(a,b,c,d,e,f,g,h,i):
    num2 = int(j+k+l+m+n+o+p+q+r)
    num2 = str(num2)
    if '0' not in num2:
        if '3' in num2 and '5' in num2 and '7' in num2:
            num2 = int(num2)
            if num >= num2:
                cnt += 1

print(cnt)

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

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

print(dfs("0"))

Solution (Python):



def judge(number):
    def digit(check_num , number):
        if int(check_num) > number:
            return 0
        
        if all(check_num.count(digit_num) > 0 for digit_num in "753"):
            
            count = 1
        else:
            
            count = 0
        
        for add_num in "753":
            count = count + digit(check_num + add_num , number)
            
        return count
        
    print(digit("0",number))

def main():
    number = int(input())
    judge(number)
    
if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
def f(s):
  if int(s)>n:
    return 0
  t=0
  if s.count("3")>0 and s.count("5")>0 and s.count("7")>0:
    t=1
  return f(s+"7")+f(s+"5")+f(s+"3")+t
print(f("0"))

Solution (Python):

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

print(dfs("0"))

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = []
for i in range(10):
    for p in itertools.product(['3','5','7'],repeat=i):
        if '3' in p and '5' in p and '7' in p:
            s.append(int(''.join(p)))
res = 0
for i,t in enumerate(s):
    if t <= n:
        res += 1
print(res)

Solution (Python):
import itertools
import bisect
n=int(input())
s=[]
for i in range(3,10):
  for p in itertools.product(['3','5','7'],repeat=i):
    if '3' in p and '5' in p and '7' in p:
      s.append(int(''.join(p)))
x=bisect.bisect_right(s,n)
print(x)

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

Solution (Python):
def STR(): return input()

def func(a, b):
    if a > b:
        return 0
    else:
        return 1

def solve_dp(arr, ii):
    dp = [[0, 0] for _ in range(ii)]
    lenarr = len(arr)
    n0 = int(n[0])
    a = lenarr
    for j in range(lenarr):
        a -= func(n0, arr[j])
    dp[0][0] = a
    dp[0][1] = 1 if n0 in arr else 0
    for i in range(1, ii):
        ni = int(n[i])
        a = lenarr
        for j in range(lenarr):
            a -= func(ni, arr[j])
        dp[i][0] = dp[i-1][0] * lenarr + dp[i-1][1] * a
        dp[i][1] = dp[i-1][1] if ni in arr else 0
    return sum(dp[ii-1])

n = STR()
l = len(n)
ans = 0

arr = [[3], [5], [7], [3, 5], [5, 7], [7, 3], [3, 5, 7]]
ans = solve_dp(arr[6], l)
for i in range(3):
    ans += solve_dp(arr[i], l)
for i in range(3, 6):
    ans -= solve_dp(arr[i], l)
for i in range(1, l):
    ans += pow(3, i) + 3 - 3 * pow(2, i)
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

def func(a, b):
    if a > b:
        return 0
    else:
        return 1

def solvedp(arr, ii):
    dp = [[0, 0] for _ in range(ii)]
    lenarr = len(arr)
    if ii == l:
        n0 = int(n[0])
        a = lenarr
        for j in range(lenarr):
            a -= func(n0, arr[j])
        dp[0][0] = a
        dp[0][1] = 1 if n0 in arr else 0
    else:
        dp[0][0] = lenarr
    for i in range(1, ii):
        if ii == l:
            ni = int(n[i])
            a = lenarr
            for j in range(lenarr):
                a -= func(ni, arr[j])
            dp[i][0] = dp[i-1][0] * lenarr + dp[i-1][1] * a
            dp[i][1] = dp[i-1][1] if ni in arr else 0
        else:
            dp[i][0] = dp[i-1][0] * lenarr
    return dp

n = STR()
l = len(n)
ans = 0

arr = [[3], [5], [7], [3, 5], [5, 7], [7, 3], [3, 5, 7]]
for ii in range(1, l + 1):
    dp = [[[0, 0]for _ in range(ii)]for _ in range(7)]
    for i in range(7):
        dp[i] = solvedp(arr[i], ii)

    res = sum(dp[6][ii-1])
    for i in range(3, 6):
        res -= sum(dp[i][ii-1])
    for i in range(3):
        res += sum(dp[i][ii-1])
    ans += res
print(ans)

Solution (Python):
N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    else:
        if '7' in s and '5' in s and '3' in s:
            ret = 1
        else:
            ret = 0
        for i in '357':
            ret += dfs(s + i)
        return ret
print(dfs("0"))

Solution (Python):
def f(a,b):


    if a==7 and b>=4: return b
    if a==7 and b<4: return b+4
    if a==5 and b in (2,3,6,7): return b
    if a==5 and b not in (2,3,6,7): return b+2
    if a==3 and b in (1,3,5,7): return b
    if a==3 and b not in (1,3,5,7): return b+1

n=input()



l=[int(i) for i in "0"+n]
dp=[[[0]*9,[0]*9] for _ in "ww"]
dp[0][0][0]=1

chk=(7,5,3)
for i,j in enumerate(l):
    if i==0: continue
    elif i==1:
        if j in chk: dp[i%2][0][f(j,0)]=1
        if j not in chk: dp[i%2][0][0]=1
        if j>7: dp[i%2][1][4]+=1
        if j>5: dp[i%2][1][2]+=1
        if j>3: dp[i%2][1][1]+=1
        dp[i%2][1][0]=1
    else:
        dp[i%2][1][0]=1
        dp[i%2][1][4]+=1
        dp[i%2][1][2]+=1
        dp[i%2][1][1]+=1
        for k in range(8):
            if dp[i%2-1][0][k] and (k==0 or j not in chk): dp[i%2][0][0]=1
            elif dp[i%2-1][0][k] and j in chk: dp[i%2][0][f(j,k)]=1

            if dp[i%2-1][0][k] and k!=0:
                if j>7: dp[i%2][1][f(7,k)]+=1
                if j>5: dp[i%2][1][f(5,k)]+=1
                if j>3: dp[i%2][1][f(3,k)]+=1
            if dp[i%2-1][1][k] and k!=0:
                dp[i%2][1][f(7,k)]+=dp[i%2-1][1][k]
                dp[i%2][1][f(5,k)]+=dp[i%2-1][1][k]
                dp[i%2][1][f(3,k)]+=dp[i%2-1][1][k]
    for k in range(9):
        dp[i%2-1][0][k]=0
        dp[i%2-1][1][k]=0

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

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

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

print(dfs('0'))

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

N = int(input())

def sft(p) :
    if int(p) > N :
        return 0
    co = 0
    if "7" in p and "5" in p and "3" in p :
        co = 1
    co += sft(p+"7") + sft(p+"5") + sft(p+"3")
    return co

print(sft("0"))

Solution (Python):
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  
def grid(n): return [s_list() for _ in range(n)]


def main():

    n = int(input())

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

        for c in '753':
            res += dfs(s + c)
        return res

    print(dfs('0'))

if __name__ == '__main__':
    main()

Solution (Python):
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  
def grid(n): return [s_list() for _ in range(n)]


def main():

    n = int(input())
    str_n = str(n)
    
    ngs = ['3','5','7']
    
    
    ans = ''
    count = 0
    for i in range(1,len(str_n)+1):
        for j in list(product(ngs, repeat=i)):
            
            for k in j:
                ans += k
            
            ngs_and_ans = set(ngs) & set(ans)
            if int(ans) <= n and len(ngs_and_ans) == 3:
                count += 1
            ans = ''
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):


n=input()
n_len=len(n)
nana=["7","5","3"]

def dfs(s):
    
    if int(s)>int(n):
        return 0
    d=1 if all(s.count(nana[i])>=1 for i in range(3) ) else 0
    for j in range(3):
        d+=dfs(s+nana[j])
    return d

ans=dfs("0")
print(ans)

Solution (Python):
N = int(input())
def dfs(S):
    if int(S) > N:
        return 0
    res = 1 if all(S.count(x) > 0 for x in '753') else 0
    for x in '753':
        res += dfs(S+x)
    return res

print(dfs('0'))

Solution (Python):
N = int(input())
s = "357"
cnt = 0
for i in range(1,10):
    for j in range(3**i):
        n = j
        t = ""
        for k in range(i):
            t+=s[n%3]
            n//=3
        if len(set(t))!=3:continue
        if int(t)<=N:cnt+=1
print(cnt)

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


def dfs(s):
    if int(s) > n:
        return 0

    ans = 1 if sorted(list(set(str(s)))) == ['0', '3', '5', '7'] else 0
    for i in '753':
        ans += dfs(s + i)

    return ans


print(dfs('0'))

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

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

    retval = 1 if len(set(x)) == 3 else 0
    for c in '753':
        retval += dfs(x + c)
    return retval


print(dfs(''))

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

def squ(x):
    if x == 0:
        return '0'
    a = ""
    while x != 0:
        x, mod = divmod(x, 4)
        a += str(mod)
    return a[::-1]


ans = 0

for x in range(10**6):
    x_squ = squ(x)
    x_str = x_squ.replace('3', '7').replace('2', '5').replace('1', '3')

    if "0" in x_str:
        continue

    if int(x_str) > n:
        break

    if len(set(x_str)) != 3:
        continue

    ans += 1

print(ans)

Solution (Python):
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)

N = int(input())

dfs(0, 0, 0, 0)
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 f(s):
    if int(s) > N:
        return 0
    res=1 if all(s.count(c)>0 for c in "357") else 0    
    for c in "357":
        res += f(s+c)
    return res    
print(f("0"))

Solution (Python):
n=int(input())
A=[3,5,7]
past=int(0)
head=int(2)
for i in range(9):
    for j in range(past,head+1):
        A.append(10*A[j]+3)
        A.append(10*A[j]+5)
        A.append(10*A[j]+7)
    past=head+1
    head=len(A)

ans=int(0)
for i in range(len(A)):
    t=0
    f=0
    s=0
    now=A[i]
    while(now>0):
        if now%10==3:
            t=1
        if now%10==5:
            f=1
        if now%10==7:
            s=1
        now=int(now/10)
    
    if t and f and s and A[i]<=n:
        ans+=1
        
print(ans)

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

print(dfs('0'))

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

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

print(dfs("0",N))

Solution (Python):
n = input()
l = len(n)
ans = 0
stack = ["7", "3", "5"]

def check753(s):
  if "7" in s and "3" in s and "5" in s:
    return True
  else:
    return False


while stack:
  s = stack.pop()
  if int(n) >= int(s) and len(s) >= 3 and check753(s):
    ans+=1
  if len(s) < l:
    for i in ["7", "5", "3"]:
      stack.append(i+s)
      
print(ans)

Solution (Python):
import itertools
N=int(input())
l=len(str(N))
s=set()
S='753'
for i in range(1,l+1):
    for j in itertools.product(S,repeat=i):
        s.add(int(''.join(j)))
li=sorted(s)
cnt=0
for i in range(len(li)):
    if(li[i]>N):
        break
    if('7' in str(li[i]) and '5' in str(li[i]) and '3' in str(li[i])):
        cnt+=1
print(cnt)

Solution (Python):
n = int(input())
 
def bfs(s):
  if int(s) > n:
    return 0
  return ('3' in s and '5' in s and '7' in s) + bfs(s+'3') + bfs(s+'5') + bfs(s+'7')
 
print(bfs('0'))

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

cnt = 0

def dfs(s):    
    global cnt
    
    if int(s) > n:
        return None
    
    else:
        if s.count('3') >= 1 and s.count('5') >= 1 and s.count('7') >= 1:
            cnt += 1
            
        dfs(s+'3')
        dfs(s+'5')
        dfs(s+'7')


dfs('0')
print(cnt)

Solution (Python):

"""

4進法で表す
各桁が
0→0
1→3
2→5
3→7で変換

"""

def change4(x):
    ret = []

    for i in range(10,-1,-1):
        ret.append(x // (4**i))
        x %= (4**i)
    ret.reverse()
    return ret

N = input()
ni = int(N)
ch = [0,3,5,7]
ans = 0

for i in range(4 ** len(N)):

    now = change4(i)

    if 1 not in now or 2 not in now or 3 not in now:
        continue

    zf = False
    flag = True
    nsum = 0
    for j in range(11):
        if now[j] == 0:
            zf = True
        elif zf:
            flag = False
            break
        else:
            nsum += (10**j) * ch[now[j]]
            

    if flag and nsum <= ni:
        ans += 1
    
    

print (ans)

Solution (Python):
def main():
    n = int(input())
    print(dfs("0",n))



def dfs(s,n):
    counter = 0
    if int(s) > n:
        return 0
    counter += 1 if (s.count("3") >= 1 and s.count("5")>= 1 and s.count("7") >= 1) else 0
    for c in "357":
        counter += dfs(s+c,n)
    return counter


if __name__ == '__main__':
    main()

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

Solution (Python):
from bisect import bisect_right

def sft(n, s):
    d = len(s[0])
    if s and d == n:
        return sorted([int(i) for i in s])
    a = []
    for i, si in enumerate(s):
        for k in range(3):
            ai = si + "357"[k]
            da = len(set(list(ai)))
            if d == n - 2 and da < 2:
                continue
            if d == n - 1 and da < 3:
                continue
            a.append(ai)
    return sft(n, a)

def main():
    n = input()
    d = len(n)
    s = []
    l = list("357")
    for i in range(3, d + 1):
        s += sft(i, l)
    print(bisect_right(s, int(n)))

if __name__ == '__main__':
    main()

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

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

Solution (Python):
import itertools

s=input()

keta = len(s)

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

ans = 0

for i in range(3,keta+1):
    for j in itertools.product(risuto, repeat=i):
        
        if '3' in j and '5' in j and '7' in j:
            if int(''.join(j)) <= int(s):
                   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())
S = len(str(N))
T = ["7","5","3"]
ans = 0
for s in range(3,S+1):
    for i in range(3**s):
        A = []
        n = i
        for j in range(s):
            A.append(n%3)
            n//=3
        if len(set(A))<3:continue
        k = "".join([T[a] for a in A])
        if int(k)<=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())

cnt = 0

def cn(n,N):
    global cnt
    
    if n == 0:
        return 0
    a = int("3"+n) 
    b = int("5"+n) 
    c = int("7"+n)
    if a <= N and "5" in n and "7" in n:
        cnt += 1
    if b <= N and "3" in n and "7" in n:
        cnt += 1
    if c <= N and "3" in n and "5" in n:
        cnt += 1
      
    if a > N:
        cn(0,N)
    else:
        cn(str(a),N)
    if b > N:
        cn(0,N)
    else:
        cn(str(b),N)
    if c > N:
        cn(0,N)
    else:
        cn(str(c),N)

cn("",N)
print(cnt)

Solution (Python):
def main():
  n=[int(i) for i in list(input())]
  l=len(n)
  
  def abc_num(n,a,b,c):
    dp=[[0]*2 for i in range(l+1)]
    dp[0][0]=1
    for i in range(l):
      if n[i]<a:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][1]*3
      elif n[i]==a:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][1]*3
      elif n[i]<b:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]+dp[i][1]*3
      elif n[i]==b:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][0]+dp[i][1]*3
      elif n[i]<c:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]*2+dp[i][1]*3
      elif n[i]==c:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][0]*2+dp[i][1]*3
      else:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]*3+dp[i][1]*3
    return sum(dp[-1])
    
        
  def ab_num(n,a,b):
    dp=[[0]*2 for i in range(l+1)]
    dp[0][0]=1
    for i in range(l):
      if n[i]<a:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][1]*2
      elif n[i]==a:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][1]*2
      elif n[i]<b:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]+dp[i][1]*2
      elif n[i]==b:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][0]+dp[i][1]*2
      else:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]*2+dp[i][1]*2
    return sum(dp[-1])
  
  def a_num(x):
    x=int(''.join([str(i) for i in x]))
    three=int(''.join(['3']*l))
    five=int(''.join(['5']*l))
    seven=int(''.join(['7']*l))
    if x<three:
      return 0
    elif three<=x<five:
      return 1
    elif five<=x<seven:
      return 2
    else:
      return 3  

  ans=abc_num(n,3,5,7)
  ans-=(ab_num(n,3,5)+ab_num(n,3,7)+ab_num(n,5,7))
  ans+=a_num(n)
  for i in range(3,l):
    ans+=3**i-3*(2**i)+3
  print(ans)  
if __name__=='__main__':
  main()

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


def dfs(s):
    if int(s) > n:
        return 0
    if s.count('7') > 0 and s.count('5') > 0 and s.count('3') > 0:
        ret = 1
    else:
        ret = 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 s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1
    else:
        cnt = 0
    cnt += dfs(s + '3')
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt
 
 
print(dfs('0'))

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

Solution (Python):


N=int(input())

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

print(dfs('0'))

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


def dfs(x):
    if x > N:
        return 0
    s = str(x)
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        ret = 1
        
    else:
        ret = 0
    ret += dfs(10 * x + 7)
    ret += dfs(10 * x + 5)
    ret += dfs(10 * x + 3)
    return ret


print(dfs(0))

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


def dfs(s):
    if int(s) > N:
        return 0
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        ret = 1
        
    else:
        ret = 0
    ret += dfs(s + "7")
    ret += dfs(s + "5")
    ret += dfs(s + "3")
    return ret


print(dfs("0"))

Solution (Python):
def main():
    N = int(input())
    N_len = len(str(N))
    from itertools import product
    s = set()
    for k in range(3, N_len + 1):
        s = s | {t for t in product("753", repeat=k)
                 if int("".join(t)) <= N and len(set(t) & set("753")) == 3}
    print(len(s))


if __name__ == '__main__':
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy,copy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    candidate = set(["3","5","7"])
    for i in range(9):
        for c in copy(candidate):
            candidate.add(c+"3")
            candidate.add(c+"5")
            candidate.add(c+"7")
    
    ans = 0
    for c in candidate:
        if int(c)<=N and 0 not in (c.count("3"),c.count("5"),c.count("7")):
            ans += 1
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
from itertools import product
ans = 0
for n in range(3,10):
    for ptn in product('753', repeat=n):
        if '7' not in ptn: continue
        if '5' not in ptn: continue
        if '3' not in ptn: continue
        v = int(''.join(ptn))
        if v <= N:
            ans += 1
print(ans)

Solution (Python):
import itertools


n = int(input())

def calculate(n,length):
    count = 0
    for i in itertools.product([3,5,7],repeat=length):
        if isValid(i) == False:
            continue
        sum = 0
        for j in range(length):
            sum = sum + i[j] * 10 ** j
        if sum <= n:
            count = count + 1

    return count

def isValid(n):
    dict = {}
    for s in n:
        if dict.get(s) == None:
            dict.__setitem__(s,1)
        else:
            dict.__setitem__(s,dict.get(s) + 1)

    s1 = dict.get(3) != None and dict.get(3) > 0
    s2 = dict.get(5) != None and dict.get(5) > 0
    s3 = dict.get(7) != None and dict.get(7) > 0

    return s1 and s2 and s3

length = len(str(n))

result = 0
for i in range(3,length+1):
    result = result + calculate(n,i)

print(result)

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


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


ans = dfs("0")

print(ans)

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

x =[]
for i in range(3,11):
    x += list(product(a, repeat = i))
y = []
for j in x:
    if '7' in j and '5' in j and '3' in j:
        y.append(j)
z = []
for k in range(len(y)):
    z.append(''.join(y[k]))
z = [int(_) for _ in z]

b = 0
for p in z:
    if p <= n:
        b += 1

print(b)