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 sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())


N = input()
digits = len(N)




DP = [[[[[-1] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(digits+1)]



DP[digits][0][1][1][1] = 1
DP[digits][1][1][1][1] = 1



DP[digits-1][0][0][0][0] = 0
DP[digits-1][1][0][0][0] = 0
DP[digits-1][0][1][0][0] = 0
DP[digits-1][0][0][1][0] = 0
DP[digits-1][0][0][0][1] = 0
DP[digits-1][1][1][0][0] = 0
DP[digits-1][1][0][1][0] = 0
DP[digits-1][1][0][0][1] = 0
DP[digits-2][0][0][0][0] = 0
DP[digits-2][1][0][0][0] = 0


DP[digits-1][0][1][1][0] = 1
DP[digits-1][0][1][0][1] = 1
DP[digits-1][0][0][1][1] = 1

import sys
sys.setrecursionlimit(10**9)



def solve(digit, tight, a7ed, a5ed, a3ed):
  global digits
  
  
  if ~(DP[digit][tight][a7ed][a5ed][a3ed]):

    return DP[digit][tight][a7ed][a5ed][a3ed]
  else: 
    if digits-digit < 3-a7ed-a5ed-a3ed:
      DP[digit][tight][a7ed][a5ed][a3ed] = 0
      return 0
    
    if tight:

      target = int(N[digit])

      
      tmp = 0 if a7ed|a5ed|a3ed else solve(digit+1,0,0,0,0)
      if target <= 2: tmp += 0
      elif target == 3: tmp += solve(digit+1, 1, a7ed, a5ed, a3ed | 1)
      elif target == 4: tmp += solve(digit+1, 0, a7ed, a5ed, a3ed | 1)
      elif target == 5: tmp += solve(digit+1, 0, a7ed, a5ed, a3ed | 1) + solve(digit+1, 1, a7ed, a5ed | 1, a3ed)
      elif target == 6: tmp += solve(digit+1, 0, a7ed, a5ed, a3ed | 1) + solve(digit+1, 0, a7ed, a5ed | 1, a3ed)
      elif target == 7: tmp += solve(digit+1, 0, a7ed, a5ed, a3ed | 1) + solve(digit+1, 0, a7ed, a5ed | 1, a3ed) + solve(digit+1, 1, a7ed | 1, a5ed, a3ed)
      else: 
        tmp += solve(digit+1, 0, a7ed, a5ed, a3ed | 1) + solve(digit+1, 0, a7ed, a5ed | 1, a3ed) + solve(digit+1, 0, a7ed | 1, a5ed, a3ed)
      DP[digit][tight][a7ed][a5ed][a3ed] = tmp
      return tmp
    else: 

      if a7ed & a5ed & a3ed: 
        tmp = 3**(digits-digit) 
        DP[digit][tight][a7ed][a5ed][a3ed] = tmp
        return tmp
      else:
        
        tmp = 0 if a7ed|a5ed|a3ed else solve(digit+1,0,0,0,0)
        
        tmp += solve(digit+1, 0, a7ed | 1, a5ed, a3ed) + solve(digit+1, 0, a7ed, a5ed | 1, a3ed) + solve(digit+1, 0, a7ed, a5ed, a3ed | 1)
        DP[digit][tight][a7ed][a5ed][a3ed] = tmp
        return tmp

print(solve(0,1,0,0,0))

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

ans = 0
p = [0]
while p:
    k = p.pop()
    if k > N:
        continue
    if '7' in str(k) and '5' in str(k) and '3' in str(k):
        ans += 1
    p.extend([k*10+3, k*10+5, k*10+7])
print(ans)

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

def f(x):
    result=""
    while x>=1:
        result+=str(x%3)
        x=int(x/3)
    result=result[::-1]
    return(result)

for M in range(len(N)+1):
    for n in range(3**M-1):
        number=f(n).zfill(M)
        if number.count("0")==0 or number.count("1")==0 or number.count("2")==0:
            pass
        else:
            number753=""
            for k in range(len(number)):
                if number[k]=="0":
                    number753+="3"
                elif number[k]=="1":
                    number753+="5"
                else:
                    number753+="7"
            if int(number753)>int(N):
                pass
            else:
                ans+=1

print(ans)

Solution (Python):
n = int(input())
dp = ["3"]
brk = False
for i in range(n):
    if brk == True:
        break
    for c in "357":
        if int(dp[i]+c)>n:
            brk = True
            break
        dp.append(dp[i]+c)
        
dp2 = ["5"]
brk = False
for i in range(n):
    if brk == True:
        break
    for c in "357":
        if int(dp2[i]+c)>n:
            brk = True
            break
        dp2.append(dp2[i]+c)

dp3 = ["7"]
brk = False
for i in range(n):
    if brk == True:
        break
    for c in "357":
        if int(dp3[i]+c)>n:
            brk = True
            break
        dp3.append(dp3[i]+c)

dp = dp+dp2+dp3
count = 0
for i in range(len(dp)):
    if all(dp[i].count(c) for c in "753"):
        count += 1
print(count)

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

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

main()

Solution (Python):

def shichi_go_san(s="0"):
    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 += shichi_go_san(s + c)
    return ret


n = int(input())
print(shichi_go_san())

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

def ternary(t):
  t = list(map(int, list(t)))
  t = list(reversed(t))
  for i in range(len(t)):
    t[i] = t[i] + 1
    d = t[i] // 3
    t[i] = t[i] % 3
    
    if d <= 0:
      break
    else:
      if i == len(t)-1:
        t.append(0)
  return ''.join(map(str, list(reversed(t))))

def scg(t):
  t = t.replace('3', '0')
  t = t.replace('5', '1')
  t = t.replace('7', '2')
  
  t = ternary(t)
  
  t = t.replace('0', '3')
  t = t.replace('1', '5')
  t = t.replace('2', '7')
  
  return t

value = '357'
while n >= int(value):
  if '3' in value and '5' in value and '7' in value:
    ans += 1
  value = scg(value)

print(ans)

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

Solution (Python):
from itertools import product
n = int(input())
ans = 0
for i in range(1, len(str(n))+1):
    for x in product('357', repeat=i):
        flag = True
        for p in '357':
            if not p in x:
                flag = False
                break
        if flag:
            if int("".join(x)) <= n:
                ans += 1
print(ans)

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

stgsn = []

def make753(nowstr,three,five,seven,isEnd):
    
    if len(nowstr) > len(str(N)):
        
        isEnd = True
        return 0
    if three and five and seven and (int(nowstr) <= N):
        stgsn.append(nowstr)

    
    if not isEnd:
        make753(nowstr+"3",True,five,seven,isEnd)
        make753(nowstr+"5",three,True,seven,isEnd)
        make753(nowstr+"7",three,five,True,isEnd)

make753("",False,False,False,False)

print(len(stgsn))

Solution (Python):
N = int(input())
all = []
nums = [3,5,7]
for i in range(8):
    tmp = []
    for n in nums:
        tmp.append(n*10+3)
        tmp.append(n*10+5)
        tmp.append(n*10+7)
    all += nums
    nums = tmp
all += nums
all.sort()
ans = 0
for a in all:
    if a > N:
        break
    if '3' in str(a) and '5' in str(a) and '7' in str(a):
        ans += 1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
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 II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

counter = 0
def main():
    N = II()
    def dp(number, has_seven, has_five, has_three):
        global counter
        if int(number+'7') <= N:
            if has_five and has_three:
                counter += 1
            dp(number+'7', True, has_five, has_three)
        if int(number+'5') <= N:
            if has_seven and has_three:
                counter += 1
            dp(number+'5', has_seven, True, has_three)
        if int(number+'3') <= N:
            if has_seven and has_five:
                counter += 1
            dp(number+'3', has_seven, has_five, True)
    dp('',False,False,False)
    print(counter)

main()

Solution (Python):
X=int(input())
def dp(N,seq):
    if N!=0:
        if min(seq.count("3"),seq.count("5"),seq.count("7"))!=0:
            if int(seq)<=X:
                p.append(seq)
    if N<10:
        dp(N+1,seq+"3")
        dp(N+1,seq+"5")
        dp(N+1,seq+"7")
p=[]
dp(0,"")
print(len(p))

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

    
    def rec(svalue, maximum):
        add = 0
        if svalue != "":
            if int(svalue) <= maximum: 
                if ('7' in svalue and '5' in svalue and '3' in svalue):
                    add = 1
            else:
                return 0

        
        sevens = rec(svalue + '7', maximum)
        fives = rec(svalue + '5', maximum)
        threes = rec(svalue + '3', maximum)
        return sevens + fives + threes + add
    
    print(rec("", N))
        

if '__main__' == __name__:
    resolve()

Solution (Python):



def makeval(in_sn):
    div = int(in_sn / 4)
    rem = in_sn % 4
    if div == 0:
        if rem == 0:
            return "X"
        elif rem == 1:
            return "3"
        elif rem == 2:
            return "5"
        elif rem == 3:
            return "7"
    else:
        ret = makeval(div)
        if rem == 0:
            return ret + "3"
        elif rem == 1:
            return ret + "5"
        elif rem == 2:
            return ret + "7"
        elif rem == 3:
            return "X"

n = int(input())

wval = 1
cnt = 0
idx = 1

while(wval <= n):
    wstr = makeval(idx)
    if ("X" in wstr) == False:
        if ("3" in wstr) == True and ("5" in wstr) == True and ("7" in wstr) == True :
            wval = int(wstr)
            cnt += 1
    
    idx += 1

cnt -= 1


print(cnt)

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

ans = [0]

def calc(s):
    if int(s) <= N:
        if "3" in s and "5" in s and "7" in s:
            ans[0] += 1
        for e in ["3", "5", "7"]:
            calc(s + e)

for e in ["3", "5", "7"]:
    calc(e)

print(ans[0])

Solution (Python):
def judge(s):
    ans = 0
    add_3 = s * 10 + 3
    if add_3 <= N:
        str_num = str(add_3)
        if str_num.count("3") and str_num.count("5") and str_num.count("7"):
            ans += 1
        ans += judge(add_3)
    add_5 = s * 10 + 5
    if add_5 <= N:
        str_num = str(add_5)
        if str_num.count("3") and str_num.count("5") and str_num.count("7"):
            ans += 1
        ans += judge(add_5)
    add_7 = s * 10 + 7
    if add_7 <= N:
        str_num = str(add_7)
        if str_num.count("3") and str_num.count("5") and str_num.count("7"):
            ans += 1
        ans += judge(add_7)
    return ans


N = int(input())

print(judge(0))

Solution (Python):
arr=[3,5,7]

global res
res = 0
ma = int(input())

def gen(num = 0):
    global res
    
    if ma < num:
        return
    else:
        st = str(num)
        if st.count('3') and st.count('5') and st.count('7'):
            res += 1

    for i in arr:
        if num == 0:
            gen(num+i)
        else:
            gen(10*num + i)

gen()
print(res)

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

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

Solution (Python):
n=int(input())
def dfs(x):
    if int(x)>n:
        return 0
    c=1 if all(x.count(l)>0 for l in "753") else 0
    for i in "753":
        c+=dfs(x+i)
    return c
print(dfs("0"))

Solution (Python):
from collections import deque


def gen753number(max_value):
    numbers = '357'
    que = deque([l for l in numbers])

    while True:
        while len(que):
            pre = que.popleft()
            if int(pre) > max_value:
                break
            if all([i in pre for i in numbers]):
                yield pre
            for n in numbers:
                que.append(pre + n)
        break


n = int(input())
print(len(list(gen753number(n))))

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

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

print(dfs('0'))

Solution (Python):
N = int(input())
ans = 0
def sft(s):
    global ans
    if int(s) >= N:
        return ans
    for x in '357':
        if int(s+x) > N:
            break
        sft(s+x)
        if '3' in s+x and '5' in s+x and '7' in s+x:
            
            ans += 1
    return ans
print(sft('0'))

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

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 "357":
        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) for c in "753") else 0
    for c in "753":
        ret += dfs(s + c)
    return ret
print(dfs("0"))

Solution (Python):
N = int(input())
ans = 0
for i in range(1, (4 ** 9)+1):
    tmp = ""
    now = i
        
    while now != 0:
        if now % 4 == 0:
            tmp += "0"
        elif now % 4 == 1:
            tmp += "3"
        elif now % 4 == 2:
            tmp += "5"
        else:
            tmp += "7"

        now //= 4

    
    tmp = str(int(tmp[::-1]))
    if "3" in tmp and "5" in tmp and "7" in tmp:
        tmp = int(tmp)
        if tmp <= N and "0" not in str(tmp):
            ans += 1
print(ans)

Solution (Python):
from itertools import product
n=input()
deg=len(n)
n=int(n)
d=['3','5','7']
d1=['3','5']
d2=['5','7']
d3=['3','7']
cnt=0
if deg<2:
     print(0)
else:
     for i in range(3,deg+1):
          d_=list(product(d,repeat=i))
          d1_=list(product(d1,repeat=i))
          d2_=list(product(d2,repeat=i))
          d3_=list(product(d3,repeat=i))
          d_=[x for x in d_ if x not in d1_]
          d_=[x for x in d_ if x not in d2_]
          d_=[x for x in d_ if x not in d3_]
          for x in d_:
               x=list(x)
               a=int(''.join(x))
               if a<=n:
                    cnt+=1
               else:
                    break
     print(cnt)

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()

  cnt=0
  for j in range(-1,3):
    for b in range(-1,3):
      for c in range(-1,3):
        for d in range(-1,3):
          for e in range(-1,3):
            for f in range(-1,3):
              for g in range(-1,3):
                for h in range(-1,3):
                  for i in range(-1,3):
                    a=0

                    if i==0:
                      a+=3
                    elif i==1:
                      a+=5
                    elif i==2:
                      a+=7

                    if h==0:
                      a+=30
                    elif h==1:
                      a+=50
                    elif h==2:
                      a+=70

                    if g==0:
                      a+=300
                    elif g==1:
                      a+=500
                    elif g==2:
                      a+=700

                    if f==0:
                      a+=3000
                    elif f==1:
                      a+=5000
                    elif f==2:
                      a+=7000

                    if e==0:
                      a+=30000
                    elif e==1:
                      a+=50000
                    elif e==2:
                      a+=70000

                    if d==0:
                      a+=300000
                    elif d==1:
                      a+=500000
                    elif d==2:
                      a+=700000

                    if c==0:
                      a+=3000000
                    elif c==1:
                      a+=5000000
                    elif c==2:
                      a+=7000000

                    if b==0:
                      a+=30000000
                    elif b==1:
                      a+=50000000
                    elif b==2:
                      a+=70000000

                    if j==0:
                      a+=300000000
                    elif j==1:
                      a+=500000000
                    elif j==2:
                      a+=700000000

                    if a>n:
                      return cnt
                    else:
                      x=list(set(str(a)))
                      if x.count('0')>0:
                        continue
                      if len(x)==3:
                        cnt+=1
  
  return cnt

print(main())

Solution (Python):



import sys

input = sys.stdin.readline

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

    res = []
    def rec(n, i, k):
        if k == 1:
            res.append(n+i*(10**(k-1)))
            return
        rec(n+i*(10**(k-1)), 3, k-1)
        rec(n+i*(10**(k-1)), 5, k-1)
        rec(n+i*(10**(k-1)), 7, k-1)

    for l in range(3, len(str(N))+1):
        rec(0, 3, l)
        rec(0, 5, l)
        rec(0, 7, l)

    cnt = 0
    for on in res:
        if on > N:
            break
        found = True
        seven = False
        five = False
        three = False
        n = on
        for j in range(len(str(on))):
            a = int(n % 10)
            n /= 10
            if a != 7 and a != 5 and a != 3:
                found = False
            if a == 7:
                seven = True
            if a == 5:
                five = True
            if a == 3:
                three = True
        if found and seven and five and three:
            cnt += 1
    print(cnt)

main()

Solution (Python):
import itertools

N = int(input())

number = [7, 5, 3]

ans = 0
for i in range(10):
    for conv in itertools.product(number, repeat=i+1):
        
        tmp = 0
        for j in range(len(conv)):
            tmp += conv[j] * 10 ** (len(conv) - j - 1)
            
        
        if ((3 in conv) and (5 in conv) and (7 in conv)) and tmp <= 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):
from itertools import product
n = int(input())
ans = 0
S = []
for i in range(10):
    S += list(product("357",repeat=i))
for s in S:
  if len(set(s)) > 2 and int("".join(s)) <= n:
    ans += 1
print(ans)

Solution (Python):
n=input()
ans=0
355
lst=[]
def generate(n,x,count,lst):
    if 0<count<len(n)+1:
        if int(x)<=int(n):
            lst.append(x)
    elif count==0:
        pass
    else:
        return lst
    generate(n,x+'3',count+1,lst)
    generate(n,x+'5',count+1,lst)
    generate(n,x+'7',count+1,lst)
        
x=''
generate(n,x,0,lst)
ans=0
for i in lst:
    san=nana=go=False
    if '3' in i:
        san=True
    if '5' in i:
        go=True
    if '7' in i:
        nana=True
    if san==nana==go==True:
        ans+=1
print(ans)

Solution (Python):
from collections import Counter
from collections import deque
N = int(input())
l = deque()

def solve(s, l):
    if len(s):
        if int(s) > N:
            l.pop()
            return

    for a in '357':
        ns = s + a
        l.append(ns)
        solve(ns, l)
    return l

solve('', l)
ans = 0
for e in l:
    c = Counter(e)
    flg = True
    for n in '357':
        if c[n] == 0:
            flg = False
            break
    if flg:
        ans += 1
print(ans)

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

cnt = 0
def func(cur):
  global cnt
  if cur>N: return
  if set(str(cur)) == {'3', '5', '7'}: cnt += 1
  func(cur*10 + 3)
  func(cur*10 + 5)
  func(cur*10 + 7)

func(0)
print(cnt)

Solution (Python):
n = int(input())
ans = 0
def dfs(num ,depth, three,five,seven):
    global ans
    if depth == 0:
        if three and five and seven and num <= n:
            ans += 1
    else:
        dfs(10*num+3, depth-1, True, five, seven)
        dfs(10*num+5, depth-1, three, True, seven)
        dfs(10*num+7, depth-1, three, five, True)
for i in range(len(str(n))):
    dfs(0,i+1,False,False,False)
print(ans)

Solution (Python):
n = input()
m = len(n)
ans = 0

for k in range(m+1):
    for i in range(3 ** k):
        li = [] 
        for j in range(k):
            li.insert(0,int((i%(3**(j+1)))/(3**j)))                
        for j in range(k):
            if li[j] == 0:
                li[j] = '3'
            if li[j] == 1:
                li[j] = '5'
            if li[j] == 2:
                li[j] = '7'
        if li != []:
            if int(''.join(li)) <= int(n) and len(set(li)) == 3:
                ans += 1
print(ans)

Solution (Python):
def dfs(a,n):
    if int(a)>n:
        return 0
    if a.count('7')>0 and a.count('5')>0 and a.count('3')>0:
        ans=1
    else:
        ans=0
    for i in '753':
        ans+=dfs(a+i,n)
    return ans

n=int(input())
print(dfs('0',n))

Solution (Python):
import itertools
n=int(input())
keta=len(str(n))
ans=0
for k in range(1,keta+1):
  for c in itertools.product(range(3),repeat=k):
    nn=""
    flag3,flag5,flag7=0,0,0
    for i in range(k):
      if c[i]==0:
        nn+="3"
        flag3=1
      elif c[i]==1:
        nn+="5"
        flag5=1
      else:
        nn+="7"
        flag7=1
    if flag3*flag5*flag7==1 and int(nn)<=n:
      ans+=1
print(ans)

Solution (Python):
from itertools import product


l753 = []
for i in range(3, 10):
    l = ['753'] * i
    for s in product(*l):
        if '7' in s and '3' in s and '5' in s:
            l753.append(int("".join(s)))
l753 = sorted(l753)
N = int(input())
count = 0
for i in l753:
    if i > N:
        break
    count += 1
print(count)

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

Solution (Python):
from itertools import product
N=input()
ans=0
for i in range(3,len(N)+1):
    A=list(product(['7','5','3'],repeat=i))
    for a in A:
        if int(''.join(a))<=int(N) and set(a)>={'7','5','3'}:
            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())

def dfs(num):
    if num and int(num) > N:
        return 0

    count = 1 if '3' in num and '5' in num and '7' in num else 0

    for s in '357':
        count += dfs(num + s)
    return count

print(dfs(''))

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) for c in '753') else 0
    for c in '753':
        ret += dfs(s + c)
    return ret

print(dfs('0'))

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

def f(i, n, T, F, S):
  if i >= Nlen:
    return 1 if n <= N and T > 0 and F > 0 and S > 0 else 0
  n *= 10
  cnt = 0
  if n == 0:
    cnt += f(i+1, n, T  , F  , S  )
  cnt += f(i+1, n+3, T+1, F  , S  )
  cnt += f(i+1, n+5, T  , F+1, S  )
  cnt += f(i+1, n+7, T  , F  , S+1)
  return cnt

print(f(0, 0, 0, 0, 0))

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


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

    for x in '753':
        ret += dfs(s + x)
    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())

def f(s):
	if int(s) > n: return 0
	p = 0
	if '7' in s and '5' in s and '3' in s:
		
		p = 1
	return f(s + '3') + f(s + '5') + f(s + '7') + p

print(f('0'))

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


def dfs(s):
    if s != '' and int(s) > N:
        return 0
    ans = int(all([s.count(c) > 0 for c in '753']))
    for c in '753':
        ans += dfs(s + c)
    return ans


print(dfs(''))

Solution (Python):
n = int(input())
sevenfivethree = []
judge = 0

def dfs(num: str):
    if int(num) > n or len(num) > 8:
        return
    else:
        if int(num+"3") <= n:
            sevenfivethree.append(num + "3")
        if int(num+"5") <= n:
            sevenfivethree.append(num + "5")
        if int(num+"7") <= n:
            sevenfivethree.append(num + "7")

        dfs(num + "3")
        dfs(num + "5")
        dfs(num + "7")

        return

dfs("3")
dfs("5")
dfs("7")

for i in range(len(sevenfivethree)):
    if sevenfivethree[i].count("3") ==0 or sevenfivethree[i].count("5") ==0 or sevenfivethree[i].count("7") ==0:
        sevenfivethree[i] = 0 
        judge = 1
print(len(set(sevenfivethree)) - (judge == 1))

Solution (Python):
import itertools
n = input()
m = len(n)

cn = 0
for i in range(3,m+1):
    for l in itertools.product(["5","7","3"],repeat = i):
        l = "".join(l)
        if int(l) > int(n): continue
        cn += 1 if "3" in l and "5" in l and "7" in l else 0
print(cn)

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

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

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

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

    
    cnt = 0
    flag = 1
    for i in "753":
        if not num.count(i):
            flag = 0
            break
    if flag:
        cnt += 1

    for i in "753":
        cnt += dfs(num + i)

    return cnt

print(dfs("0"))

Solution (Python):

import sys

            

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

    return ret
            




def solve(N: str):
    print(dfs("0",int(N)))



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)  
    solve(N)

if __name__ == '__main__':
    main()

Solution (Python):
def ls_ternary(n, limit):
  ls = ["3"*n]
  while int(ls[-1]) <= limit and len(ls) < 3**n:
    ls.append(ternary_plus(ls[-1], 1))
    
  return ls[:-1]

def ternary_plus(chars, d):
  n = len(chars)
  tg = chars[n-d]
  if tg=='7':
    return ternary_plus(chars[:n-d]+'3'+chars[n-d+1:], d+1)
  else:
    if tg=='3':
      nxt = '5'
    else:
      nxt = '7'
    return chars[:n-d] + nxt + chars[n-d+1:]

s = input()
l = len(s)
hs = []
for i in range(l):
  if i+1<3:
    hs.append(0)
  else:
    hs.append(3**(i+1)-3*(2**(i+1))+3)

if l<3:
  print(0)
elif l==3:
  print(len(list(filter(lambda x: '3' in x and '5' in x and '7' in x, ls_ternary(l, int(s))))))
else:
  a = len(list(filter(lambda x: '3' in x and '5' in x and '7' in x, ls_ternary(l, int(s)))))
  print(a+sum(hs[:l-1]))

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

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

    for c in "357":
        ret += dfs(s+c)
    return ret

print(dfs("0"))

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

import itertools
ans = 0
candidate = [3,5,7]

for j in range(3,len(str(N))+1):
    for i in itertools.product(candidate, repeat=j):
        if int("".join(map(str, list(i)))) <= N:
            if 3 in list(i) and 5 in list(i) and 7 in list(i):
                ans += 1


print(ans)

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

nums = ['3', '5', '7']
add3 = lambda x: x + '3'
add5 = lambda x: x + '5'
add7 = lambda x: x + '7'

cnt = 0
for _ in range(k-1):
    num_tmp = []
    num_tmp.append(list(map(add3, nums)))
    num_tmp.append(list(map(add5, nums)))
    num_tmp.append(list(map(add7, nums)))
    nums = sum(num_tmp, [])

    for i in range(len(nums)):
        if '3' in nums[i] and '5' in nums[i] and '7' in nums[i] and int(nums[i]) <= N:
            cnt += 1

print(cnt)

Solution (Python):
n = input()

def f(s):
    if int(s) > int(n):
        return 0
    if all(['3' in s,'5' in s,'7' in s]):
        ans.append(1)
    for t in '3','5','7':
        f(s+t)

ans=[]
f('0')
print(sum(ans))

Solution (Python):
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools


from itertools import permutations
import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

l=[3,5,7]



nnn=10
cnt=0
inputx=int(input())
endflag=0
for n in range(3,nnn):
    for xxx in itertools.product(l,repeat=n):
        num = int("".join([str(e) for e in xxx]))
        if num>inputx:
            endflag=1
            break
        else:
            res=sorted(set(xxx))
            
            if res==[3,5,7]:
                
                cnt+=1
            else:
                continue
    if endflag==1:
        print(cnt)
        break
if endflag==0:
    print(cnt)

Solution (Python):
n = input()
ans = 0
num753 = [[]for _ in range(len(n)+1)]

def create753(n): 
  num753[0].append('0')
  num753[1].append('3')
  num753[1].append('5')
  num753[1].append('7')
  
  for i in range(1,n):
    for j in num753[i]:
      for k in '357':
        num_next = j + k
        num753[i+1].append(num_next)
  
create753(len(n))

for i in num753:
  for j in i:
    if all(j.count(c) > 0 for c in '753') and (1 <= int(j) <=int(n)):
      ans += 1

print(ans)

Solution (Python):
import itertools
import bisect
n=input()
l=[]
for i in range(3,len(n)+1):
    for j in itertools.product([3,5,7],repeat=i):
        if len(set(j))==3:
            l.append(int(''.join(map(str,j))))
l.sort()
print(bisect.bisect_right(l,int(n)))

Solution (Python):
N = int(input())
def n_ary(l,d): 
    if d == 1:
        return(l)
    n = len(l)
    ll = n_ary(l,d-1)
    lll = []
    for i in l:
        for j in ll[n*(n**(d-2)-1)//(n-1):]:
            lll.append(i+j)
    return(ll+lll)
possible = [i for i in n_ary(['3','5','7'],9)] 
print(len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= N)]))