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 solve(string):
    n = string
    ans = 0
    for i in range(3, len(n) + 1):
        tmp = ("".join(x) for x in product("753", repeat=i) if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if len(x) < len(n) or x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))

Solution (Python):
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(3, len(str(n)) + 1):
        tmp = (int("".join(x))
               for x in product("753", repeat=i)
               if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))

Solution (Python):
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(3, len(str(n)) + 1):
        tmp = (int("".join(x))
               for x in product("753", repeat=i)
               if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))

Solution (Python):
from math import ceil, log10
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(2, ceil(log10(n))):
        tmp = (int("".join(x))
               for x in product("753", repeat=i + 1)
               if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))

Solution (Python):
from math import ceil, log10
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(2, ceil(log10(n))):
        tmp = (int("".join(x))
               for x in product("753", repeat=i + 1)
               if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))

Solution (Python):
from math import ceil, log10
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(2, ceil(log10(n))):
        tmp = [
            int("".join(x))
            for x in product("753", repeat=i + 1)
            if "7" in x and "5" in x and "3" in x
        ]
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))

Solution (Python):
from math import ceil, log10
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(2, ceil(log10(n))):
        tmp = [
            int("".join(x))
            for x in product("753", repeat=i + 1)
            if "7" in x and "5" in x and "3" in x
        ]
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))

Solution (Python):

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

N = int(input())


ans = 0


def check(s: str)->bool:
    return '3' in s and '5' in s and '7' in s


def dfs(s: str)->int:
    ret = 0
    if int(s) > N:
        return 0
    else:
        if check(s):
            ret += 1
        r3 = dfs(s+"3")
        r5 = dfs(s+"5")
        r7 = dfs(s+"7")

        ret += r3+r5+r7
    return ret


print(dfs("0"))

Solution (Python):
from collections import deque
N = int(input())
q = deque()
q.append(0)
memo = []
while q:
    x = q.pop()
    if x < 10**9:
        if len(set(str(x))) == 3:
            memo.append(x)
        q.append(10*x+3)
        q.append(10*x+5)
        q.append(10*x+7)

print(len([num for num in memo if num <= N]))

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

def dfs(x):
    if len(set(str(x))) == 3:
        dp.append(x)

    if x < 10**9:
        dfs(x*10+3)
        dfs(x*10+5)
        dfs(x*10+7)

dfs(0)
print(len([item for item in dp if item <= N]))

Solution (Python):
from itertools import product

N = int(input())

cnt = 0
for k in range(3, 10+1):
    for x in product("753", repeat=k):
        if set(x) < set("753"):
            continue
        v = int("".join(x))
        if v <= N:
            cnt += 1
print(cnt)

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

def func(s):

    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 += func(s+c)    

    return count

print(func("0"))

Solution (Python):


N = int(input())


def func(s):
    global N
    if int(s) > N:
        return 0

    ret = 1 if all(s.count(c) > 0 for c in '753') else 0

    for char in '753':
        ret += func(s + char)
    return ret


print(func('0'))

Solution (Python):
def func(var):
    res = 1 if all(c in str(var) for c in '357') else 0
    if var > N:
        return 0
    else:
        for v in 3, 5, 7:
            res += func(var * 10 + v)
    return res


N = int(input())
res = 0
for v in 3, 5, 7:
    res += func(v)
print(res)

Solution (Python):

import math
import sys

num_l = []
mx = 10**9

def get_n(s, k):
  if k == 0:
    if ('3' in s) and ('5' in s) and ('7' in s) and (int(s) <= mx):
      num_l.append(int(s))
  else:
    for c in ['3', '5', '7']:
      get_n(s+c, k-1)
    if len(s) == 0 or s[-1] == '0':
      get_n(s, k-1)

if __name__ == "__main__":
  mx = int(sys.stdin.readline().rstrip())
  get_n("", len(str(mx)))
  print(len(num_l))

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
from sys import stdin
N=int(stdin.readline().rstrip())
ans=0
for i in range(3,10):
    for j in list(itertools.product("753",repeat=i)):
        if int("".join(j)) <= N and len(set("".join(j)))==3:
            ans+=1
print(ans)

Solution (Python):
import itertools
from sys import stdin
N=int(stdin.readline().rstrip())
ans=0
for i in range(3,11):
    for j in list(itertools.product("753",repeat=i)):
        if int("".join(j)) <= N and len(set("".join(j)))==3:
            ans+=1
print(ans)

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

dp = []

def dfs(x):
    if check(x):
        dp.append(x)

    if (x <= 10**9):
        dfs(10*x+3)
        dfs(10*x+5)
        dfs(10*x+7)

def check(x):
    set_x = set(list(str(x)))
    if set_x >= {'3','5','7'} and set_x <= {'3','5','7'}:
        return True


dfs(0)
print(len([item for item in dp if item <= N]))

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


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

print(c("0"))

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

Solution (Python):

import itertools

a=raw_input()
n=int(a)
res=0
for i in xrange(1,len(a)+1):
 for s in itertools.product('753',repeat=i):
  m=int("".join(s))
  if len(set(s))==3 and m<=n:
   res+=1
print res

Solution (Python):
n = int(input())
count = 0
base = [[0],[],[],[],[],[],[],[],[],[],[]]
for digit in range(10):
  for i in base[digit]:
    num_3 = i+3*10**digit
    num_5 = i+5*10**digit
    num_7 = i+7*10**digit
    next_digit = digit + 1
    if num_3 <= n:
      if set(str(num_3)) == {'3','5','7'}:
        count += 1
      base[next_digit].append(num_3)
    if num_5 <= n:
      if set(str(num_5)) == {'3','5','7'}:
        count += 1
      base[next_digit].append(num_5)
    if num_7 <= n:
      if set(str(num_7)) == {'3','5','7'}:
        count += 1
      base[next_digit].append(num_7)
print(count)

Solution (Python):






import numpy as np





n = int(input())





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

print(func("0"))

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

m = 0
c = [0, 3, 5, 7]
count = 0

def p753(m):
    i = 0
    s = 0 if m > 0 else c[0]
    while m > 0:
        s += 10**i * c[m % 4]
        i += 1
        m = m // 4
    return s

p = p753(m)

while p <= n:
    mt = m
    f = [False, False, False, False]
    
    while mt > 0:
        f[mt % 4] = True
        if mt % 4 == 0:
            break
        mt = mt // 4
    if (not f[0]) and f[1] and f[2] and f[3]:
        count += 1
    m += 1
    p = p753(m)

print(count)

Solution (Python):
list = []

def dfs(length,num):
    global list
    if len(num) == length:
        list.append(num)
        return

    for i in ['3','5','7']:
        newnum = num + i
        dfs(length,newnum)

    return


N = input()
ans = 0

for i in range(1,len(N) + 1):
    dfs(i,'')

for i in list:
    if ('3' in i) and ('5' in i) and ('7' in i):
        if int(N) >= int(i):
            ans += 1

print(ans)

Solution (Python):



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


def f(i):
    if i <= 10 ** 9:
        sitigosan.append(i)
        f(i * 10 + 3)
        f(i * 10 + 5)
        f(i * 10 + 7)


f(3)
f(5)
f(7)


sitigosan = sorted(sitigosan)
count = 0
for sgs in sitigosan:
    if sgs > n:
        break
    str_sgs = str(sgs)
    if "3" in str_sgs and "5" in str_sgs and "7" in str_sgs:
        count += 1
print(count)

Solution (Python):


N = int(input())

All753 = {"33","35","37","53","55","57","73","75","77"}


for i in range(9):
    list1 = {s+"3" for s in All753 if N >= int(s+"3")}
    list2 = {s+"5" for s in All753 if N >= int(s+"5")}
    list3 = {s+"7" for s in All753 if N >= int(s+"7")}
    All753 = All753 | list1 | list2 | list3

list = {s for s in All753 if "3" in s and "5" in s and "7" in s}

print(len(list))

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

def dfs(s):
  if int(s) > n:
    return 0
  ret = 1 if all(c in s for c in '357') else 0
  for c in '357':
    ret += dfs(s + c)
  return ret

print(dfs('0'))

Solution (Python):
from itertools import product
import math
n = int(input())

ans = 0
for k in range(3, 1 -int(-math.log10(n)//1)):
    for li in product('357', repeat=k):
        if len(set(li)) < 3:
            continue
        if int(''.join(li)) > n:
            continue
        ans += 1

print(ans)

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


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

print(dfs("0"))

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

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

print(num753("0"))

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

def dfs(s):
  if int(s) > n:
    return 0
  ret = 1 if all(c in s for c in '357') else 0
  for c in '357':
    ret += dfs(s + c)
  return ret

print(dfs('0'))

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

def out(s):
    
    i_s = int(s)
    if i_s <= n:
        
        if all([True if str(i_s).count(s) > 0 else False for s in '753']):
            global cnt
            
            cnt +=1 
            
            
        [out(str(i_s) + s) for s in '753']

out('0')
print(cnt)

Solution (Python):
import itertools
n = int(input())
ori = [3, 5, 7]
num = []
num.append(0)
ans = []
i = 1
while i < 10:
    num.append(list(itertools.product(ori, repeat=i)))
    for k in range(len(num[i])):
        if (3 in num[i][k]) and (5 in num[i][k]) and (7 in num[i][k]):
            ans.append(int(''.join([str(x) for x in num[i][k]])))
    i += 1
count = 0
for f in ans:
    if n >= f:
        count += 1
print(count)

Solution (Python):
def main():
    global result, S
    S = int(input())
    result = 0
    bfs(0, '')
    print(result)


def bfs(i, s):
    global result, S
    if s != '' and int(s) <= S and len(set(s)) == 3:
        result += 1
    if i == len(str(S)):
        return
    i += 1
    bfs(i, s + '3')
    bfs(i, s + '5')
    bfs(i, s + '7')


if __name__ == '__main__':
    main()

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

tri_d = {0:3, 1:5, 2:7}
tri = [0,1,2]

def tri_dec(lst):
  d = 0
  for l in lst:
    d *= 10
    d += tri_d[l]
  return d

def tri_inc(lst):
  lst[-1] += 1
  i = 1
  while lst[-i] > 2:
    if i == len(lst):
      lst.insert(0, -1)
    lst[-i] -= 3
    lst[-(i+1)] += 1
    i += 1
  if set(lst) != {0,1,2}:
    tri_inc(lst)
  return lst

count = 0
while tri_dec(tri) <= N:
  count += 1
  tri = tri_inc(tri)
print(count)

Solution (Python):
def main():
    global results, S
    S = int(input())
    S_str = str(S)
    results = []
    for i in range(3, len(S_str) + 1):
        bfs(i, '')
    print(len(results))


def bfs(i, s):
    global results, S
    if i == 0:
        if int(s) <= S and len(set(s)) == 3:
            results.append(s)
        return
    i -= 1
    bfs(i, s + '3')
    bfs(i, s + '5')
    bfs(i, s + '7')


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    global results, S
    S = int(input())
    S_str = str(S)
    results = []
    for i in range(3, len(S_str) + 1):
        bfs(i, '')
    print(len(results))


def bfs(i, s):
    global results, S
    if i == 0:
        if int(s) <= S and len(set(s)) == 3:
            results.append(s)
        return
    i -= 1
    bfs(i, s + '3')
    bfs(i, s + '5')
    bfs(i, s + '7')


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    global results, S
    S = int(input())
    S_str = str(S)
    results = []
    for i in range(len(S_str)):
        digits = len(S_str) - i
        if digits < 3:
            break

        
        bfs(digits, '')

    print(len(results))


def bfs(i, s):
    global results, S
    if i == 0:
        if int(s) <= S and len(set(s)) == 3:
            results.append(s)
        return
    i -= 1
    bfs(i, s + '3')
    bfs(i, s + '5')
    bfs(i, s + '7')


if __name__ == '__main__':
    main()

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

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

print(count('0'))

Solution (Python):
N = int(input())
cands = '753'

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

print(dfs('0'))

Solution (Python):
N = int(input())
ans = 0
def dfs(n, f1, f2, f3):
    if n > N:
        return
    elif f1 and f2 and f3:
        global ans
        ans += 1

    dfs(n*10+7, True, f2, f3)
    dfs(n*10+5, f1, True, f3)
    dfs(n*10+3, f1, f2, True)

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

Solution (Python):
from itertools import product
n = int(input())
cnt = 0
for i in range(3,10):
    for m in product(["3","5","7"],repeat = i):
        if "3" in m and "5" in m and "7" in m and int("".join(m))<=n:
            cnt += 1
print(cnt)

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


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

print( dfs('0') )

Solution (Python):

N = int(input())

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

print(dfs('0'))

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

cnt = 0
for i in range(3,n+1):
    l = []
    x = ""
    def fa(x,l,i):
        if len(x) == i:
            if int(x) <= N:
                if x.count("3") >= 1 and x.count("5") >= 1 and x.count("7"):
                    l.append(x)
            return 
        else:
            x += "3"
            fa(x,l,i)
            fb(x,l,i)
            fc(x,l,i)
    def fb(x,l,i):
        if len(x) == i:
            if int(x) <= N:
                if x.count("3") >= 1 and x.count("5") >= 1 and x.count("7"):
                    l.append(x)
            return 
        else:
            x += "5"
            fa(x,l,i)
            fb(x,l,i)
            fc(x,l,i)
    def fc(x,l,i):
        if len(x) == i:
            if int(x) <= N:
                if x.count("3") >= 1 and x.count("5") >= 1 and x.count("7"):
                    l.append(x)
            return 
        else:
            x += "7"
            fa(x,l,i)
            fb(x,l,i)
            fc(x,l,i)
    fa(x,l,i)
    fb(x,l,i)
    fc(x,l,i)
    k = sorted(set(l))
    cnt += len(k)

print(cnt)

Solution (Python):


N = int(input())


def f(s):
    if len(s) > 0 and int(s) > N:
        return 0

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

    for c in '753':
        ans += f(s + c)

    return ans


print(f(""))

Solution (Python):
import queue
s = input()

l = len(s)

def P(n,i):
    product = 1
    for x in range(i):
        product *= (n-x)
    return product

def f(n):
    product = 1
    for x in range(n):
        prodcut *= (n-x)
    return product

if(l<3):
    print("0")
    exit(0)

res = 0
'''
for i in range(3,l):
    res += P(i,3)*(3**(i-3))



digit = list(range(1,l+1))

numlist = [0]*l
'''
q = queue.Queue()

q.put('')

while not q.empty():
    x = q.get()
    if(x !='' and int(x)>int(s)):
        continue
    else:
        q.put(x+'3')
        q.put(x+'5')
        q.put(x+'7')
    if('3' in x and '5' in x and '7' in x):
        res += 1
print(res)

Solution (Python):
N = int(input())
def nsin(x,n):
    if(int(x/n)):
        return nsin(int(x/n),n)+str(x%n)
    return str(x%n)

def to357(s):
    s = s.replace('3', '7')
    s = s.replace('2', '5')
    s = s.replace('1', '3')
    return s

ans = 0
for i in range(1, N + 1):
    num_3 = nsin(i, 4)
    if '0' in num_3 or '1' not in num_3 or '2' not in num_3 or '3' not in num_3:
        continue

    num_10 = int(to357(num_3))
    if num_10 > N:
        break

    ans += 1
print(ans)

Solution (Python):
import itertools
n = int(input())
l = []
l.extend(list(itertools.product([3,5,7], repeat=i)) for i in range(3,10))
l = [int("".join(map(str,j))) for i in l for j in i if 7 in j and 5 in j and 3 in j]
print(sum([1 for i in l if n>=i]))

Solution (Python):
def keta(n, elements):
    results = elements
    for i in range(n - 1):
        results = [r * 10 + e for e in elements for r in results]
    return results

N = int(input())

num753 = set()
for i in range(3,10):
    n1 = keta(i, set([3, 5, 7]))
    n2 = keta(i, set([3, 5]))
    n3 = keta(i, set([5, 7]))
    n4 = keta(i, set([3, 7]))
    num753 |= set(n1) - set(n2) - set(n3) - set(n4)
num753 = sorted(num753)

ans = 0
for i in num753:
    if i <= N:
        ans += 1
print(ans)

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


def count(N, s='0'):
    if int(s) > N:
        return 0
    ret = 1 if all([d in s for d in '357']) else 0
    for d in '357':
        ret += count(N, s+d)
    return ret


tmp = count(N)

print(tmp)

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

print(dsf('0'))

Solution (Python):
N = input()
nums = ['3', '5', '7']
for i in range(len(N)):
  for num in nums:
    if(len(num) == i):
      nums.append(num + '3')
      nums.append(num + '5')
      nums.append(num + '7')
cnt = 0
for num in nums:
  if(int(num) <= int(N) and '3' in num and '5' in num and '7' in num):
    cnt += 1
print(cnt)

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

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

print(func('0'))

Solution (Python):
n=int(input())
list_753=["3","5","7"]
for i in range(len(str(n))):
    for num in list_753:
        if len(num)==i:
            list_753.append(num+"3")
            list_753.append(num+"5")
            list_753.append(num+"7")
        else:
            pass

counter=0
for i in range(len(list_753)):
    if int(list_753[i])<=n and "3" in list_753[i] and "5" in list_753[i] and "7" in list_753[i]:
        counter+=1
    else:
        pass
print(counter)

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

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

print(f("0"))

Solution (Python):
N = int(input())
digit = len(str(N))
list753 = ["3", "5", "7"]  

for i in range(digit):
    for n in list753:
        if len(n) == i:
            list753.append(n + "7")
            list753.append(n + "5")
            list753.append(n + "3")


counter = 0
for num in list753:
    if int(num) <= N and 0 not in [num.count("3"), num.count("5"), num.count("7")]:
        counter += 1
print(counter)

Solution (Python):
N = int(input())
def chk(s):
  if int(s) > N:
    return 0
  else:
    flag=True
    for c in '753':
      if not c in s:
        flag=False
        break
    count=0
    if flag:
      count=1
    for c in '753':
      count += chk(s+c)
    return count
print(chk('0'))

Solution (Python):


N = int(input())

ans = 0
cursor = "357"


def increment(cursor):
    l = len(cursor)
    ret = [''] * (l + 1)
    if cursor[-1] == '7':
        ret[-1] = '3'
        ret[-2] = '3'
    elif cursor[-1] == '5':
        ret[-1] = '7'
    elif cursor[-1] == '3':
        ret[-1] = '5'

    for i in range(l-1):
        if ret[-(2 + i)] == '3':
            if cursor[-(2 + i)] == '7':
                ret[-(2 + i)] = '3'
                ret[-(3 + i)] = '3'
            elif cursor[-(2 + i)] == '5':
                ret[-(2 + i)] = '7'
            elif cursor[-(2 + i)] == '3':
                ret[-(2 + i)] = '5'
        else:
            ret[-(2 + i)] = cursor[-(2 + i)]

    return ''.join(ret)


while N >= int(cursor):
    if '7' in cursor and '5' in cursor and '3' in cursor:
        ans += 1
    cursor = increment(cursor)

print(ans)

Solution (Python):
'''
3^9 = 19683
3^10 = 59049
これくらいの数なら全探索して十分間に合う
'''

import itertools
from functools import reduce

n = int(input())
ans = 0

for length in range(3, len(str(n)) +1):
	base = itertools.product('357', repeat=length)
	
	for i in base:
		if len(set(i))== 3: 
			i_int = int(reduce(lambda x, y: x + y, i))
			if i_int <= 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):
'''
3^9 = 19683
3^10 = 59049
これくらいの数なら全探索して十分間に合う
'''

import itertools
from functools import reduce

n = int(input())
ketasuu = len(str(n))
ans = 0

base = itertools.product('357', repeat=ketasuu)


for i in base:
	if len(set(i))== 3: 
		i_int = int(reduce(lambda x, y: x + y, i))
		if i_int <= n:
			ans += 1

for k in range(3, ketasuu):
	temp = 3**k - 3*1**k - 3 * (2**k - 2* 1**k)
	ans += temp

print(ans)

Solution (Python):
def n_numbers(n: int) -> int:
    ret = 0
    while True:
        n = n // 10
        ret += 1
        if n <= 0:
            break
    return ret

def gen_numbers(n: int) -> int:
    if n <= 1:
        yield 3
        yield 5
        yield 7
    else:
        for g in gen_numbers(n-1):
            for m in ["3","5","7"]:
                yield int(m + str(g))

def validate(n: int) -> bool:
    three = False
    five = False
    seven = False
    while True:
        k = n % 10
        if k == 3:
            three = True
        elif k == 5:
            five = True
        elif k == 7:
            seven = True
        n = n // 10
        if three and five and seven:
            return True
        if n <= 1:
            break
    return False


n = int(input())

k = n_numbers(n)

if k < 3:
    print(0)
else:
    ret = 0
    for i in range(3, k+1):
        for target in gen_numbers(i):
            if target <= n and validate(target):
                ret += 1
    print(ret)

Solution (Python):
import numpy as np
from itertools import product
s = input()
n = int(s)

digit = len(s)

selected_num = []
for order in range(3, 10, 1):
    for i in product('753', repeat = order):
        concat_str = "".join(i)
        if(('7' in concat_str) and ('5' in concat_str) and ('3' in concat_str)):
            selected_num.append(int(concat_str))

selected_num_array = np.array(selected_num)

print(np.sum(selected_num_array <= n))

Solution (Python):
import numpy as np
s = input()
n = int(s)

digit = len(s)

all_combinations = []

for i1 in ("3", "5", "7"):
    for i2 in ("3", "5", "7"):
        for i3 in ("3", "5", "7"):
            for i4 in ("3", "5", "7"):
                for i5 in ("3", "5", "7"):
                    for i6 in ("3", "5", "7"):
                        for i7 in ("3", "5", "7"):
                            for i8 in ("3", "5", "7"):
                                for i9 in ("3", "5", "7"):
                                    all_combinations.append(i1+i2+i3+i4+i5+i6+i7+i8+i9)

for i1 in ("3", "5", "7"):
    for i2 in ("3", "5", "7"):
        for i3 in ("3", "5", "7"):
            for i4 in ("3", "5", "7"):
                for i5 in ("3", "5", "7"):
                    for i6 in ("3", "5", "7"):
                        for i7 in ("3", "5", "7"):
                            for i8 in ("3", "5", "7"):
                                all_combinations.append(i1+i2+i3+i4+i5+i6+i7+i8)

for i1 in ("3", "5", "7"):
    for i2 in ("3", "5", "7"):
        for i3 in ("3", "5", "7"):
            for i4 in ("3", "5", "7"):
                for i5 in ("3", "5", "7"):
                    for i6 in ("3", "5", "7"):
                        for i7 in ("3", "5", "7"):
                            all_combinations.append(i1+i2+i3+i4+i5+i6+i7)

for i1 in ("3", "5", "7"):
    for i2 in ("3", "5", "7"):
        for i3 in ("3", "5", "7"):
            for i4 in ("3", "5", "7"):
                for i5 in ("3", "5", "7"):
                    for i6 in ("3", "5", "7"):
                        all_combinations.append(i1+i2+i3+i4+i5+i6)

for i1 in ("3", "5", "7"):
    for i2 in ("3", "5", "7"):
        for i3 in ("3", "5", "7"):
            for i4 in ("3", "5", "7"):
                for i5 in ("3", "5", "7"):
                    all_combinations.append(i1+i2+i3+i4+i5)

for i1 in ("3", "5", "7"):
    for i2 in ("3", "5", "7"):
        for i3 in ("3", "5", "7"):
            for i4 in ("3", "5", "7"):
                all_combinations.append(i1+i2+i3+i4)

for i1 in ("3", "5", "7"):
    for i2 in ("3", "5", "7"):
        for i3 in ("3", "5", "7"):
            all_combinations.append(i1+i2+i3)

selected_num = []
for i in all_combinations:
    if not ('7' in i):
        continue
    if not ('5' in i):
        continue
    if not ('3' in i):
        continue

    selected_num.append(int(i))

selected_num_array = np.array(selected_num)

print(np.sum(selected_num_array <= n))

Solution (Python):
import sys


def make753(r, l):
  if r == 1:
    return l
  else:
    l = l + [i*10 + 3 for i in l] + [i*10 + 5 for i in l] + [i*10 + 7 for i in l]
    l = list(set(l))
    return make753(r-1, l)

def main():
  input = sys.stdin.readline
  n = str(input().strip())
  R = len(n)
  N = int(n)
  l = [7, 5, 3]
  L = make753(R, l)
  ans = 0
  for i in L:
    if i > N:
      continue
    elif set([int(j) for j in str(i)]) != set([7, 5, 3]):
      continue
    else:
      ans += 1
  print(ans)


if __name__ == '__main__':
  main()

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

ans = 0

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

print(dfs("0"))

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

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

print(dfs(""))

Solution (Python):

import sys



def solve(lines):
    Numbers = []
    def iter(s, i, n):
        if i == n:
            if ( s.find('3') >= 0 and s.find('5') >= 0 and s.find('7') >= 0 ):
                Numbers.append(int(s))
        else:
            iter(s+"3", i+1, n)
            iter(s+"5", i+1, n)
            iter(s+"7", i+1, n)

    N = int(lines.pop(0))
    for digit in range(3, len(str(N))+1):
        iter("",0, digit)

    print(len(list((filter(lambda x: x <= N, Numbers)))))
    














lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

Solution (Python):



from itertools import product

def main():
  n = int(input())
  length_of_n = len(str(n))

  
  _sum = sum( [3**(i) - 3*(2**(i)) + 3*1 for i in range(3, length_of_n)] )

  
  for x in product(*([('3', '5', '7')]*length_of_n)):
    x = ''.join(x)
    if int(x) <= n and all([c in x for c in list('357')]):
      _sum += 1
  print(_sum)


  pass

if __name__=='__main__':
  main()

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


L=[3,5,7]

def dfs(s):
    count=0
    for i in L:
        p=s*10+i
        if p<=n:
            if set([int(j) for j in str(p)])==set(L):
                count+=dfs(p)+1 
            else:
                count+=dfs(p)
    return count

print(dfs(0))

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

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

print(dfs('0'))

Solution (Python):
import itertools
N= input()
Number=int(N)
count=[]
x=0
n=3
count=0
def check (S):
    S=str(S)
    if S.count('3')!=0 and S.count('5')!=0 and S.count('7')!=0 and int(S)<=Number:
        return 1

def dfs(x):
    global count
    if check(x)==1:
        count+=1
    if x<=Number:
        dfs(10*x+3)
        dfs(10*x+5)
        dfs(10*x+7)


dfs(0)
print(count)