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

import itertools
N = input()
Nlen = len(N)
N = int(N)
l = ["3","5","7"]

ans = 0
for k in range(3,Nlen+1):
    for cs in itertools.product(l,repeat=k):
        tmp_num = ""
        for i, c in enumerate(cs):
            tmp_num = c + tmp_num

        if tmp_num.count("3") == 0 or tmp_num.count("5") == 0 or tmp_num.count("7") == 0:
            continue

        if int(tmp_num) <= N:
            ans += 1

print(ans)

Solution (Python):
from itertools import product

N = int(input())

ans = 0
for i in range(3, 10):
    for ss in product('357', repeat=i):
        if len(set(ss)) < 3: continue
        k = int(''.join(ss))
        if k > N: break
        ans += 1
print(ans)

Solution (Python):


import itertools
n=int(input())


r=0
k=len(str(n))
for j in range(3,k+1):
  l=('3', '5', '7' )
  for i in itertools.product(l, repeat=j):
    if not ( '3' in i and '5' in i and '7' in i):
      continue
    x=int(''.join(map(str,i)))
    if x > n:
      break
    r=r+1
print(r)

Solution (Python):
def c_755(N):
    from itertools import product
    is_upper = False
    ans = 0
    for digit in range(3, 10):
        for s in product('357', repeat=digit):
            s = ''.join(s)
            if s.count('3') == 0 or s.count('5') == 0 or s.count('7') == 0:
                continue
            if int(s) <= N:
                ans += 1
    return ans

N = int(input())
print(c_755(N))

Solution (Python):
from itertools import product


def main():
    N = int(input())
    L = len(str(N))
    result = 0
    if N < 357:
        print(0)
        return

    for i in range(3, L+1):
        for p in product("357", repeat=i):
            c = [p.count(i) for i in ("3", "5", "7")]
            x = int("".join(p))
            if x > N:
                break
            if all(c):
                result += 1

    print(result)
    return


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product
N = int(input())
ans = 0
for k in range(3,11):
    for i in product([0,3,5,7],repeat=k):
        if set(i) != {3,5,7}:
            continue
        if sum([10**j*v for j,v  in enumerate(i)]) <= N:
            ans += 1
print(ans)

Solution (Python):
N = int(input())
cnt = 0
S = ''
Q = [[0, 0, 0, S]]
while Q:
  q0 = Q[0]
  Q = Q[1:]
  for i, s in enumerate(['3', '5', '7']):
    q = [q for q in q0]
    q[i] += 1
    q[3] += s
    if int(q[3]) <= N:
      Q.append(q)
      if q[0] and q[1] and q[2]:
        cnt += 1
print(cnt)

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

def f(xs):
    res = 0
    for i in xs:
        res = 10 * res + i
    return res

def dfs(xs):
    ans = 1 if f(xs) <= n and 3 in xs and 5 in xs and 7 in xs else 0
    if len(xs) == 9:
        return ans
    for i in [3,5,7]:
        xs.append(i)
        ans += dfs(xs)
        xs.pop(-1)
    return ans

print(dfs([]))

Solution (Python):
from itertools import product
n = int(input())
if n <= 356:
	print(0)
else:
	ans = 0
	shi_list = ["3", "5", "7"]
	shi_set = {"3", "5", "7"}
	for i in range(3, len(str(n))+1):
		for num in product(shi_list, repeat=i):
			x = int("".join(num))
			if x <= n and set(list(str(x))) & shi_set == shi_set:
				ans += 1
	print(ans)

Solution (Python):
import itertools
import collections

def check(itr_list,N):
    tmp = collections.Counter(itr_list)
    if tmp[3] > 0 and tmp[5] > 0 and tmp[7] > 0:
        s_N = ''
        for i in itr_list:
            s_N += str(i)
        if int(s_N) <= N:
            return True

    return False


S = input()
N = int(S)

tmp = [7,5,3]
ans = 0

for keta in range(3,len(S)+1):
    itr = []
    itr = list(itertools.product(tmp, repeat=keta))

    for i in itr:
        if check(i,N):

            ans += 1
print(ans)

Solution (Python):
import itertools


N = int(input())
L = [int(''.join(l)) for i in range(3, 10) for l in list(itertools.product(['3', '5', '7'], repeat=i)) if '3' in l and '5' in l and '7' in l]
L = [l for l in L if l <= N]

print(len(L))

Solution (Python):
def main():
    N = int(input())
    retval = 0
    expected = set([3, 5, 7])
    stack = [(0, set())]
    while len(stack):
        current, used = stack.pop()
        if current <= N and used == expected:
            retval += 1
        for i in [3, 5, 7]:
            next_val = current * 10 + i
            if next_val > N:
                continue
            next_used = set(used)
            next_used.add(i)
            stack.append((next_val, next_used))
    print(retval)


if __name__ == "__main__":
    main()

Solution (Python):

N = int(input())

def count(pos, val, stat):
    ret = 0
    for i, num in enumerate([3, 5, 7]):
        if val + num * (10 ** pos) <= N: 
            stat_tmp = stat | (1 << i)
            if stat_tmp == 7: ret += count(pos + 1, val + num * (10 ** pos), stat_tmp) + 1
            else: ret += count(pos + 1, val + num * (10 ** pos), stat_tmp)
        else: break
    return ret

print(count(0, 0, 0))

Solution (Python):
from itertools import product

N = int(input())
num_digits = len(str(N))

num_shichigosans = 0
for d in range(3, num_digits):
    for num_string in product(["3", "5", "7"], repeat=d):
        if len(set(num_string)) < 3:
            continue
        num_shichigosans += 1

for num_string in product(["3", "5", "7"], repeat=num_digits):
    if len(set(num_string)) < 3:
        continue
    num = int("".join(num_string))
    if num <= N:
        num_shichigosans += 1
print(num_shichigosans)

Solution (Python):
from collections import deque
n = int(input())
q = deque()
q.append('')
res = set()
while q:
    m = q.popleft()
    for c in '357':
        if int(m+c) > n: continue
        q.append(m+c)
    for c in '357':
        if c not in m: break
    else:
        res.add(m)
print(len(res))

Solution (Python):
from itertools import product as p
n=input()
N=int(n)
ans=0

for j in range(1,len(n)+1):
  for i in p(["3","5","7"],repeat=j):
    s="".join(i)
    v=int(s)
    if "3" in s and "5" in s and "7" in s and v<=N:
      ans+=1

print(ans)

Solution (Python):
import itertools
N = int(input())
ans = 0
for k in range(3,len(str(N))+1):
    for ptn in itertools.product((3,5,7), repeat=k):
        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
            continue
        a = int(''.join(list(map(str,ptn))))
        if a <= N:
            ans += 1
print(ans)

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())

nums = []
for comb in product(['0', '7', '5', '3'], repeat=9):
    candidate = str(int(''.join(comb)))
    if all((x in candidate) for x in ['7', '5', '3']) \
       and '0' not in candidate:
        nums.append(int(candidate))
nums.sort()

ans = 0
for n in nums:
    if n <= N:
        ans += 1
    else:
        break
print(ans)

Solution (Python):

def main():
    buf = input()
    N = int(buf)
    table = []
    for i in range(1, 10):
        create_table("", 0, i, table)
    count = 0
    for i in table:
        if i <= N:
            count += 1
        else:
            break
    print(count)

def create_table(num, current_digit, maximum_digit, table):
    if current_digit < maximum_digit:
        create_table(num + "3", current_digit + 1, maximum_digit, table)
        create_table(num + "5", current_digit + 1, maximum_digit, table)
        create_table(num + "7", current_digit + 1, maximum_digit, table)
    else:
        appearance = [0, 0, 0]
        for _, x in enumerate(num):
            if x == "3":
                appearance[0] += 1
            elif x == "5":
                appearance[1] += 1
            elif x == "7":
                appearance[2] += 1
            else:
                return
        if min(appearance) >= 1:
            table.append(int(num))
        return

if __name__ == '__main__':
    main()

Solution (Python):

import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    
    import numpy
    def dprint(*args, **kwargs):
        
        
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') 
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') 
    atexit.register(lambda :sys.stdout.close())     
    
N, = getIntList()

re = 0
def check(now, d):
    global re
    if now >N: return
    if d[0]>0 and d[1]>0 and d[2]>0:
        re+=1
    now*=10
    d[0]+=1
    check( now+ 7, d)
    d[0]-=1
    d[1]+=1
    check( now+ 5, d)
    d[1]-=1
    d[2]+=1
    check( now+ 3, d)
    d[2]-=1
check(0, [0,0,0])    
print(re)

Solution (Python):
from itertools import product

N = int(input())
P = []

for i in range(len(str(N))):
    P += list(product(["7", "5", "3"], repeat=i + 1))

ans = 0
for p in P:
    if ("7" not in p) or ("5" not in p) or ("3" not in p):
        continue
    else:
        p = int("".join(p))
        ans += (p <= N)

print(ans)

Solution (Python):
from itertools import product
N = int(input())
ans = 0
for l in range(1, 11):
    for p in product("357", repeat=l):
        v = "".join(p)
        if "3" in v and "5" in v and "7" in v and int("".join(p)) <= N:
            ans += 1
print(ans)

Solution (Python):
import itertools
ans=0
N=int(input())
for K in range(1,10):
    S=itertools.product(["3","5","7"],repeat=K)
    for seq in S:
        X=set()
        for i in seq:
            X.add(i)
        if len(X)!=3:
            continue
        T="".join(seq)
        if 1<=int(T)<=N:
            ans+=1
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    l = len(str(n))
    r = 0
    for i in range(3,l+1):
        for a in itertools.product(['3','5','7'], repeat=i):
            if '3' not in a or '5' not in a or '7' not in a:
                continue
            if i < l:
                r += 1
                continue
            t = int(''.join(a))
            if t <= n:
                r += 1

    return r


print(main())

Solution (Python):
from itertools import product

N = input()
ans = 0
for i in range(3,10):
  for b in product("753", repeat=i):
    if int("".join(b))<=N and "7" in b and "5" in b and "3" in b:
      ans += 1
print ans

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()

ct = 0
for d in range(1,10):
    for i in range(3**d):
        k = i
        v = 0
        ptn = 0
        for j in range(d):
            if k % 3 == 0:
                v = v * 10 + 3
                ptn |= 1
            elif k % 3 == 1:
                v = v * 10 + 5
                ptn |= 2
            else:
                v = v * 10 + 7
                ptn |= 4
            k //= 3
        if v <= n and ptn == 7:
            ct += 1
print(ct)