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
N = int(input())
cnt = 0
for i in range(3, len(str(N))+1):
    for p in product(["7", "5", "3"], repeat = i):
        if "7" in p and "5" in p and "3" in p:
            p = int("".join(p))
            if p <= N:
                cnt += 1
print(cnt)

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

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

Solution (Python):
n = int(input())
sftnum = [3,5,7]

ans = 0

for i in sftnum:
    for j in sftnum:
        for k in sftnum:
            for ii in sftnum:
                for jj in sftnum:
                    for kk in sftnum:
                        for iii in sftnum:
                            for jjj in sftnum:
                                for kkk in sftnum:
                                    num = i*100000000+j*10000000+k*1000000+ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                                    if num > n:
                                        break
                                    elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                                        ans = ans +1

for j in sftnum:
    for k in sftnum:
        for ii in sftnum:
            for jj in sftnum:
                for kk in sftnum:
                    for iii in sftnum:
                        for jjj in sftnum:
                            for kkk in sftnum:
                                num = j*10000000+k*1000000+ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                                if num > n:
                                    break
                                elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                                    ans = ans +1

for k in sftnum:
    for ii in sftnum:
        for jj in sftnum:
            for kk in sftnum:
                for iii in sftnum:
                    for jjj in sftnum:
                        for kkk in sftnum:
                            num = k*1000000+ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                            if num > n:
                                break
                            elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                                ans = ans +1


for ii in sftnum:
    for jj in sftnum:
        for kk in sftnum:
            for iii in sftnum:
                for jjj in sftnum:
                    for kkk in sftnum:
                        num = ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                        if num > n:
                            break
                        elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                            ans = ans +1

for jj in sftnum:
    for kk in sftnum:
        for iii in sftnum:
            for jjj in sftnum:
                for kkk in sftnum:
                    num = jj*10000+kk*1000+iii*100+jjj*10+kkk
                    if num > n:
                        break
                    elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                        ans = ans +1

for kk in sftnum:
    for iii in sftnum:
        for jjj in sftnum:
            for kkk in sftnum:
                num = kk*1000+iii*100+jjj*10+kkk
                if num > n:
                    break
                elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                    ans = ans +1

for iii in sftnum:
    for jjj in sftnum:
        for kkk in sftnum:
            num = iii*100+jjj*10+kkk
            if num > n:
                break
            elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                ans = ans +1

print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')



N = ""


def set_inputs():
    global N
    N = get_str()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    n = int(N)
    ans = 0
    candidates = []
    for i in range(3, len(N)+1):
        candidates.extend(itertools.product([3, 5, 7], repeat=i))
    for c in candidates:
        if 3 in c and 5 in c and 7 in c:
            v = sum(map(lambda x: x[1] * (10 ** x[0]), enumerate(reversed(c))))
            if v <= n:
                ans += 1
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

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

ans = 0
def dfs(s, target):
  global ans
  target = target + s

  if int(target) > N:
    return False

  if target.count("3") >= 1 and target.count("5") >= 1 and target.count("7") >= 1:
    ans += 1
  
  if dfs("3", target):
    return True
  
  if dfs("5", target):
    return True
  
  if dfs("7", target):
    return True
  
  
dfs("0" ,'')
print(ans)

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

ans = 0
def dfs(s, sum):
  global ans
  sum = sum + s


  if int(sum) > N:
    return False

  sum = str(int(sum))
  if sum.count("3") >= 1 and sum.count("5") >= 1 and sum.count("7") >= 1:
    ans += 1
  
  if dfs("3", sum):
    return True
  
  if dfs("5", sum):
    return True
  
  if dfs("7", sum):
    return True
  
  
dfs("0" ,'')
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):
N = int(input())


def count753(number):

    if int(number) > N:
        return 0

    if number == '0':
        number = ''

    if '7' not in number or '5' not in number or '3' not in number:
        result = 0
    else:
        result = 1

    result += count753('7' + number)
    result += count753('5' + number)
    result += count753('3' + number)

    return result


print(count753('0'))

Solution (Python):
from itertools import product

N = input()
l1 = ['3','5','7']

P = []
for i in range(len(N)):
  P += list(product(l1, repeat=i+1))

N = int(N)
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):
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
  if s.count("3")>=1 and s.count("5")>=1 and s.count("7")>=1:
    ans=1
  else:
    ans=0
  for c in "753":
    ans+=dfs(s+c)
  return ans
print(dfs("0"))

Solution (Python):
n=int(input())
x=[0,3,5,7]
p=[]
flag=True
flag2=True
for c1 in x:
  for c2 in x:
    for c3 in x:
      for c4 in x:
        for c5 in x:
          for c6 in x:
            for c7 in x:
              for c8 in x:
                for c9 in x:
                  line=[c1,c2,c3,c4,c5,c6,c7,c8,c9]
                  sum_=0
                  if line.count(7)>0 and line.count(3)>0 and line.count(5)>0:
                    for i in range(9):
                      if flag==False and line[i] in [3,5,7]:
                        flag2=False
                        break
                      if line[i]==0:
                        flag=False
                      sum_+=line[i]*10**i
                    if flag2==False:
                      flag=True
                      flag2=True
                      continue
                    p.append(sum_)
                    flag=True
p.sort()
for i in range(len(p)):
  if p[i]>n:
    print(i)
    exit()
print(i+1)

Solution (Python):
import math
def rec(A, s, d, f):
    if d == f:
        return
    A.append(s)
    rec(A, s + "3", d+1, f)
    rec(A, s + "5", d+1, f)
    rec(A, s + "7", d+1, f)

N = int(input())
digit = int(math.log10(N)) + 1
A = []
rec(A, "", 0, digit+1)
Asize = len(A)
cnt = 0
for i in range(Asize):
    if "3" in A[i] and "5" in A[i] and "7" in A[i] and int(A[i]) <= N:
        cnt += 1
print(str(cnt))

Solution (Python):

from collections import Counter
N = int(input())
l = ["0", "3", "5", "7"]
ans = ["0" for _ in range(9)]
cnt = 0
for a in l:
    ans[0] = a
    for b in l:
        ans[1] = b
        for c in l:
            ans[2] = c
            for d in l:
                ans[3] = d
                for e in l:
                    ans[4] = e
                    for f in l:
                        ans[5] = f
                        for g in l:
                            ans[6] = g
                            for h in l:
                                ans[7] = h
                                for i in l:
                                    ans[8] = i
                                    ans_i = int("".join(ans))
                                    ans_c = Counter(str(ans_i))
                                    if ans_i <= N and "0" not in str(ans_i) and len(ans_c.keys()) == 3 and len(str(ans_i)) >= 3:
                                        cnt += 1
print(cnt)

Solution (Python):
from itertools import product

N = int(input())

cnt = 0
for i in range(3, len(str(N))+1):
  for p in product(["7", "5", "3"], repeat = i):
    if "7" in p and "5" in p and "3" in p:
      p = int("".join(p))
      if p <= N:
        cnt += 1
print(cnt)

Solution (Python):
from sys import exit

N = int(input())






three = ['357', '375', '537', '573', '735', '753']
cand = ['3' , '5' , '7']
ans = 0
s = set()
def rladd(cur):
    global ans,N,s
    if(int(cur) > N) or cur in s: return False
    s.add(cur)
    ans+=1
    for i in range(len(cur)):
        for c in cand:
            temp = list(cur)
            temp.insert(i,c)
            rladd("".join(temp))
for th in three:
    rladd(th)

print(ans)

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

def dfs(i):
    global ans
    if int(i) > N:
        return
    if all(i.count(c) for c in '753'):
        ans += 1
    dfs(i + '3')
    dfs(i + '5')
    dfs(i + '7')
    
dfs('0')

print(ans)

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

if N < 357:
    print(0)
else:
    dig = int(math.log10(N)) + 1
    number = [[0] * dig for i in range(3**dig)]
    num = ['3','5','7']
    ans = 0

    for i in range(dig):
        for j in range(3**dig):
            number[j][-i-1] = num[int((j/(3**i))%3)]
    
    i = 0
    while i < len(number):
        if '3' not in number[i] or '5' not in number[i] or '7' not in number[i]: 
            number.pop(i)
        else:
            number[i] = int(''.join(number[i]))
            if N < number[i]:
                break
            i += 1

    for j in range(3,dig):
        ans += 3**j - 3 * (2**j) + 3
    print(ans+i)

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):
def create_table(m, n=[], result=[]):
    if n and int(''.join(map(str,n))) > m: return result
    r = [3, 5, 7]
    if 3 in n and 7 in n and 5 in n: result.append(n)
    for x in r:
        create_table(m, n+[x], result)
    return result

n = int(input())
print(len(create_table(n)))

Solution (Python):
num = int(input())
def to3(x,n):
  if (int(x/n)):
    return to3(int(x/n),n) + str(x%n)
  return str(x%n)
ch = ["3","5","7"]
ans = 0
for i in range(3 ** len(str(num))+1):
  s = to3(i,3)
  for u in range(len(str(num))-len(s)+2):
    if u > 0:
      s = "0" + s
    k1 = 0
    k2 = 0
    k3 = 0
    ss = ""
    for j in range(len(s)):
      if s[j] == "0":k1 = 1
      elif s[j] == "1":k2 = 1
      else: k3 = 1
      ss += ch[int(s[j])]
    if k1 and k2 and k3 and int(ss) <= num:ans += 1
print(ans)

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

answer = 0
for n in range(1,10):
  for l in itertools.product(['7','3','5'], repeat=n):
    if '7' in l and '5' in l and '3' in l:
      answer += (int(''.join(l))<=N)

print(answer)

Solution (Python):
N = int(input())
L1 = ['3', '5', '7']
L2 = ['3', '5', '7']
for i in range(1, 9):
    for x in L2:
        if len(x) == i:
            for y in L1:
                L2.append(''.join([x, y]))
L2 = [int(x) for x in L2 if '3' in x and '5' in x and '7' in x]
L3 = [1 for x in L2 if x <= N]
print(len(L3))

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

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

print(dfs('0'))

Solution (Python):
import itertools

N = input()
N1 = int(N)
N2 = len(N)

num753_comb = []
for i in range(N2):
  num753_comb.append([0,3,5,7])
All_comb = list(itertools.product(*num753_comb))

count = 0
for i in range(len(All_comb)):
 tmp = list(All_comb[i])
 tmp_num = 0
 judge0,judge3,judge5,judge7 = 0,0,0,0

 for j in range(N2):
   tmp_num += tmp[j]*(10**(N2-1-j))   
   if((tmp_num > 0)and(tmp[j] == 0)): judge0 += 1
   elif(tmp[j] == 3): judge3 += 1
   elif(tmp[j] == 5): judge5 += 1
   elif(tmp[j] == 7): judge7 += 1
   
 if(tmp_num <= N1):
   if((judge3>=1)and(judge5>=1)and(judge7>=1)and(judge0 == 0)):
      count += 1     
print(count)

Solution (Python):
c = ["3","5","7"]
sl = {"3","5","7"}
def cal(n):
    f   = True
    while f:
        cnt =0
        sl_c = sl.copy()
        for i in sl_c:
            if int(i) > n:
                f = False
            elif "3" in i and "5"  in i and "7" in i :
                
                cnt+=1
            for j in c:
                sl.add(i+j)
    return cnt
n  = int(input())
print(cal(n))

Solution (Python):
N = int(input())
l = ['3','5','7']

def dfs(s):
    if int(s)>N:
        return 0
    res = sum([dfs(s+c) for c in l])
    if all([1 if c in s else 0 for c in l]):
        res += 1
    return res

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
import numpy as np
N = input()
digit = len(N)
ans = 0
if int(N) < 357:
    print(ans)
else:
    for i in range(3, len(N)):
        ans += 3**i - 3 * 2**i + 3
    for v in itertools.product('753', repeat=digit):
        if (len(set(list(v)))==3) & (int(''.join(list(v))) <= int(N)):
            ans +=1
    print(ans)

Solution (Python):


















import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))

N = int(input())

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

print(dfs("0"))

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

digit_N = len(str(N))

def make_753(a,N_limit,n=None):
    if n==None:
        n = len(str(max(a)))
    tmp = 10 ** n
    return [tmp*3 + i for i in a if tmp*3+i <= N_limit] + \
            [tmp*5 + i for i in a if tmp*5+i <= N_limit] + \
            [tmp*7 + i for i in a if tmp*7+i <= N_limit]

list_753 = [[3,5,7] for _ in range(digit_N)]
for i in range(1,digit_N):
    list_753[i] = make_753(list_753[i-1],N,i)

def check_753(num):
    check_3 = 0
    check_5 = 0
    check_7 = 0
    num = str(num)
    for c in num:
        if check_3 == 0 and c == "3":
            check_3 = 1
        elif check_5 == 0 and c == "5":
            check_5 = 1
        elif check_7 == 0 and c == "7":
            check_7 = 1
    return check_3 * check_5 * check_7

out = 0
for tmp in list_753[2:]:
    for num in tmp:
        out += check_753(num)
print(out)

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

N = int(int(input()))

l = []

def f(n):
    if len(n) < 10:
        a = n + '7'
        b = n + '5'
        c = n + '3'
        if '7' in a and '5' in a and '3' in a:
            l.append(int(a))
        if '7' in b and '5' in b and '3' in b:
            l.append(int(b))
        if '7' in c and '5' in c and '3' in c:
            l.append(int(c))
        f(a)
        f(b)
        f(c)

f('')

l.sort()

for i in range(len(l)):
    if int(l[i]) > N:
        print(i)
        break

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

ans = 0
for n1 in ['0','3','5','7']:
	for n2 in ['0','3','5','7']:
		for n3 in ['0','3','5','7']:
			for n4 in ['0','3','5','7']:
				for n5 in ['0','3','5','7']:
					for n6 in ['0','3','5','7']:
						for n7 in ['0','3','5','7']:
							for n8 in ['0','3','5','7']:
								for n9 in ['0','3','5','7']:
									target = int(n1+n2+n3+n4+n5+n6+n7+n8+n9)
									if N <target:
										continue
										
									if 0 <str(target).count('0'):
										continue
										
									if str(target).count('3')==0:
										continue
										
									if str(target).count('5')==0:
										continue
										
									if str(target).count('7')==0:
										continue
									
									ans +=1
print(ans)

Solution (Python):
n=int(input())
num=[]
def dfs(s,x):
    if x==len(str(n)):
        return
    else:
        num.append(int(s+"3"))
        num.append(int(s+"5"))
        num.append(int(s+"7"))
        dfs(s+"3",x+1)
        dfs(s+"5",x+1)
        dfs(s+"7",x+1)
dfs("",0)
num=sorted(set(num))
ans=0
for i in num:
    if i<=n and str(i).count("3")*str(i).count("5")*str(i).count("7")!=0:
        ans+=1
print(ans)

Solution (Python):
def dfs(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 += dfs(s + c)
    return ret


n = int(input())
print(dfs("0"))

Solution (Python):
N = int(input())
ans = 0
def dfs(n=0,a=0,b=0,c=0):
    if n > N:
        return
    if a*b*c > 0:
        global ans
        ans += 1
    dfs(10*n+3,a+1,b,c)
    dfs(10*n+5,a,b+1,c)
    dfs(10*n+7,a,b,c+1)

dfs()
print(ans)

Solution (Python):
from collections import deque

N = int(input())
ans = 0
option = ["7","5","3"]
dq = deque()
for s in option:
    dq.append(s)

def judge(string):
    bit = [0]*3
    chenge = {"7":0, "5":1, "3":2}
    for s in string:
        bit[chenge[s]] = 1
    return all(bit)

while dq:
    n = dq.popleft()
    if int(n) <= N and judge(n):
        ans += 1
    if int(n) > N:
        continue
    for i,s in enumerate(option):
        dq.append(n+s)

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

S = input()
n = int(S)

def create357(length):
    if length == 1:
        return [["3",2],["5",3],["7",5]]
    else:
        ans = []
        for s in create357(length-1):
            ans.append([s[0]+"3",s[1]*2])
            ans.append([s[0]+"5",s[1]*3])
            ans.append([s[0]+"7",s[1]*5])
        return ans

if n < 1000:
    ans = 0
    for st,i in create357(3):
        if i%30 == 0 and n >= int(st):
            ans += 1
    print(ans)

else:
    ans = 0
    digit = len(S)
    for d in range(2,digit-1):
        length = d+1
        ans += 3**length+3-3*2**length
    for st,i in create357(digit):
        if i%30 == 0 and n >= int(st):
            ans += 1
    print(int(ans))

Solution (Python):
import itertools
from collections import Counter
import bisect
a = []
for i in range(3, 10):
    for j in itertools.product(["3", "5", "7"], repeat=i):
        if len(Counter(j)) == 3:
            a.append(int("".join(j)))
n = int(input())
print(bisect.bisect_right(a, n))

Solution (Python):
N = input()
A = ['7','5','3','']
num = ['']
for i in range(len(N)):
    num2 = []
    for n in num:
        for a in A:
            num2.append(n+a)
    num = num2

ans = []
for m in num:
    if len(set(m)) == 3 and int(m) <= int(N):
        ans.append(m)

print(len(set(ans)))