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):
n = int(input())
ans = 0
def dfs(s):
    global ans
    if int(s) > n:
        return
    seven = 0
    five = 0
    three = 0
    for i in range(len(s)):
        if s[i] == "7":
            seven = 1
        elif s[i] == "5":
            five = 1
        elif s[i] == "3":
            three = 1
    if seven == 1 and five == 1 and three == 1:
        ans += 1

    dfs(s + "7")
    dfs(s + "5")
    dfs(s + "3")
    return
dfs("7")
dfs("5")
dfs("3")
print(ans)

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

def dfs(s):
  ret = 0
  if int(s) > n:
    return 0
  if all(s.count(c) > 0 for c in '753'):
    ret = 1
  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())


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

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


tmp=["3", "5", "7"]
for i in range(1, len(n)):
    next=[]
    for j in tmp:
        for k in ["3", "5", "7"]:
            next.append(j+k)
    tmp=tmp+next

tmp=list(set(tmp))
N_753=[]
for i in tmp:
    if "3" in i and "5" in i and "7" in i:
        N_753.append(int(i))


N_753.sort()

print(bisect.bisect_right(N_753, N))

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


def dfs(num, add_num):
    num *= 10
    num += add_num

    if num > N:
        return

    num_list.append(num)

    dfs(num, 7)
    dfs(num, 5)
    dfs(num, 3)

    return num_list


dfs(3, 3)
dfs(3, 5)
dfs(3, 7)
dfs(5, 3)
dfs(5, 5)
dfs(5, 7)
dfs(7, 3)
dfs(7, 5)
dfs(7, 7)


ans = 0
tmp = 0
target = set(['7', '5', '3'])

for n in num_list:
    tmp = 0
    for t in target:
        if t in str(n):
            tmp += 1
    if tmp == 3:
        ans += 1
print(ans)

Solution (Python):
import itertools

N = int(input())
ans = 0
arr = ['3','5','7']
for repeat in range(3,11):
    ite = itertools.product(arr, repeat=repeat)
    for l in ite:
        if '3' in l and '5' in l and '7' in l:
            num = int(''.join(l))
            if num > N:
                break
            else:
                ans += 1
            
print(ans)

Solution (Python):
n = input()
digit = len(n)
a753 = 0
a75 = 0
a73 = 0
a53 = 0
now = 0
i = digit - 1

while now < digit:
  tmp = int(n[i])
  add = 3 ** now
  sun = (3 ** (now+1) - 3) // 2
  add2 = 2 ** now
  sun2 = 2 ** (now+1) - 2
  if tmp == 8 or tmp == 9:
    a753 = sun + 3 * add
    a75 = sun2 + 2 * add2
    a73 = sun2 + 2 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 7:
    a753 += 3 * add
    a75 += 2 * add2
    a73 += 2 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 6:
    a753 = sun + 2 * add
    a75 = sun2 + 1 * add2
    a73 = sun2 + 1 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 5:
    a753 += 2 * add
    a75 += 1 * add2
    a73 = sun2 + 1 * add2
    a53 += 2 * add2
  elif tmp == 4:
    a753 = sun + 1 * add
    a75 = sun2 + 0 * add2
    a73 = sun2 + 1 * add2
    a53 = sun2 + 1 * add2
  elif tmp == 3:
    a753 += 1 * add
    a75 = sun2 + 0 * add2
    a73 += 1 * add2
    a53 += 1 * add2
  else:
    a753 = sun + 0 * add
    a75 = sun2 + 0 * add2
    a73 = sun2 + 0 * add2
    a53 = sun2 + 0 * add2
    a = 3 * now - 3
  now += 1
  i -= 1
all1 = (10 ** digit - 1) // 9
a = 3 * digit
if int(n) < 7 * all1:
  a -= 1
if int(n) < 5 * all1:
  a -= 1
if int(n) < 3 * all1:
  a -= 1

print(a753 - a75 - a73 - a53 +a)

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

a = []


def func(s):
    if s:
        a.append(int(s))
    if len(s) == len(str(n)):
        return
    func(s + '3')
    func(s + '5')
    func(s + '7')


func('')

print(len([x for x in a if x <= n and len(set(str(x))) == 3]))

Solution (Python):
import itertools
a = input()
b = list("357")
c = 0
for j in range(3, len(a) + 1):
    for i in itertools.product(b, repeat=j):
        if int("".join(i)) <= int(a) and "3" in i and "5" in i and "7" in i:
            c += 1
print(c)

Solution (Python):

import copy
N = int(input())

keta = len(str(N))

l = ['3', '5', '7']
kotae = set()
kotae.add('0')

for i in range(keta):
    kari = copy.copy(kotae)
    for m in kari:
        for n in l:
            k = m + n
            if int(k) <= N:
                kotae.add(k)

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

print(count)

Solution (Python):

import copy
N = int(input())

keta = len(str(N))

l = ['3', '5', '7']
kotae = set()
kotae.add('0')

for i in range(keta):
    kari = copy.copy(kotae)
    for m in kari:
        for n in l:
            k = m + n
            if int(k) <= N:
                kotae.add(k)

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

print(count)

Solution (Python):
import itertools
import math
n = input()

chars = ["3", "5", "7"]
ndigits = int(math.log10(n)) + 1

count = 0
for digit in range(3, ndigits + 1):
    for string in itertools.product(chars, repeat=digit):
        if(string.count("3") == 0):
            continue
        if(string.count("5") == 0):
            continue
        if(string.count("7") == 0):
            continue
        if n >= int("".join(string)):
            count += 1

print(count)

Solution (Python):

N = int(input())



def ternary (n):
    if n == 0:
        return '0'
    nums = []
    while n:
        n, r = divmod(n, 3)
        nums.append(str(r))
    return ''.join(reversed(nums))

l = []

for i in range(3**9):
    tmp = ternary(i)
    tmp_list = list(tmp)
    tmp2 = ''


    if '0' in tmp_list and '1' in tmp_list and '2' in tmp_list :
        for j in range(len(tmp)):
            if tmp[j] == '0':
                tmp2 += '3'
            elif tmp[j] ==  '1':
                tmp2 += '5'
            elif tmp[j] == '2':
                tmp2 += '7'
        tmp2 = int(tmp2)
        l.append(tmp2)

for i in range(3**9):
    tmp = ternary(i)
    tmp_list = list(tmp)
    tmp2 = ''


    if '0' in tmp_list and '1' in tmp_list and '2' in tmp_list :
        for j in range(len(tmp)):
            if tmp[j] == '1':
                tmp2 += '3'
            elif tmp[j] ==  '2':
                tmp2 += '5'
            elif tmp[j] == '0':
                tmp2 += '7'
        tmp2 = int(tmp2)
        l.append(tmp2)

ans = 0

l = list(set(l))




for i in range(len(l)):
    if l[i] <= N :
        ans += 1

print(ans)

Solution (Python):
N = int(input())
lst = ["3", "5", "7"]
ans = 0
while lst:
    a = lst.pop(0)
    if int(a) <= N:
        for c in ["3", "5", "7"]:
            if int(a + c) <= N:
                lst.append(a + c)
        if all(a.count(c) > 0 for c in ["3", "5", "7"]):
            ans += 1
            
print(ans)

Solution (Python):
import itertools

n = int(input())
num = []
for i in range(3, 10):
    for j in itertools.product("357", repeat = i):
        if "3" in j and "5" in j and "7" in j:
            num.append("".join(j))
count = 0
for i in num:
    if int(i) <= n:
        count += 1
print(count)

Solution (Python):
import math
import itertools


def solve():
    n = read()
    result = think(n)
    write(result)


def read():
    return read_int(1)[0]


def read_int(n):
    return list(map(int, input().rstrip().split()[:n]))


def think(n):
    if n < 357:
        return 0
    digits = math.ceil(math.log10(n))
    if digits % 10 == 0:
        digits += 1

    count = 0
    dictionary = ['3', '5', '7']
    for d in range(3, digits + 1):
        for list_of_012 in itertools.product([0, 1, 2], repeat=d):
            buf = ''
            for elem in list_of_012:
                buf += str(dictionary[elem])
            if int(buf) <= n and buf.count('3') >= 1 and buf.count('5') >= 1 and buf.count('7') >= 1:
                
                count += 1
    return count


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

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

nums_753 = []
list_357 = ["3","5","7"]
upper_limit = N
def create_nums_of_357(s):

    for i in list_357:
        news = s + i
        if int(news) > upper_limit:
            continue
        save_bool = True
        for j in list_357:
            if j not in news:
                save_bool=False
                break
        if save_bool:
            nums_753.append(news)
        create_nums_of_357(news)


create_nums_of_357("")

print(len(nums_753))

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

ns = '753'

def dfs(s):
  cnt = 0
  if int(s) > N:
    return cnt
  cnt += all(c in s for c in ns) 
  cnt += sum(dfs(s + c) for c in ns)
  return cnt


ans = 0
for s in itertools.product('753', repeat=3):
  ans += dfs("".join(s))
print(ans)

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

def f(s):
    if int(s) > n:
        return 0
    if all(c in s for c in "753"):
        ret =1
    else:
        ret = 0
    for c in  "753":
        ret += f(s + c)
    return ret
print(f("0"))

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

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

print(dfs('0'))

Solution (Python):
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 shichigosan(n):
    if n < 10:
        s = {3, 5, 7}
    else:
        s = shichigosan(n//10)
        ss = shichigosan(n//10)
        for i in ss:
            s.add(i*10+3)
            s.add(i*10+5)
            s.add(i*10+7)
    return s

ans = 0
for s in shichigosan(N):
    if s <= N:
        for c in '753':
            if str(s).count(c) == 0:
                break
        else:
            ans += 1

print(ans)

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

def solve() :
    ret = 0
    lst = [0]
    pre, cur = 0, len(lst)
    for _ in range(10) :
        for i in range(pre, cur) :
            for j in [3, 5, 7] :
                s = lst[i]*10+j
                if s > S :
                    return ret
                lst.append(s)
                s = str(s)
                if '3' in s and '5' in s and '7' in s :
                    ret += 1
        pre, cur = cur, len(lst)

print(solve())

Solution (Python):
def dfs(s):
    if int(s) > n:
        return 0
    return all([c in s for c in '753']) + sum([dfs(s + c) for c in '753'])


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

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


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

Solution (Python):
N = input()
digit = len(N)


dp = [[[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(digit+2)]
dp[0][0][0][0][0][0] = 1

for i in range(digit):
  num = int(N[i])
  for j in range(2):
    for nonzero in range(2):
      for seven in range(2):
        for five in range(2):
          for three in range(2):
            for n in [0,3,5,7]:
              if (nonzero and (n == 0)) or ((j == 0) and (n > num)):
                continue
              else:
                dp[i+1][j or (n < num)][nonzero or (n != 0)]\
                [seven or (n == 7)][five or (n == 5)][three or (n == 3)]\
                += dp[i][j][nonzero][seven][five][three]

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

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


List = []
n = len(str(N))
ans = 0
if n >= 3:
    if n > 3:
        for i in range(2,n-1):
            ans += (3**(i+1)-3*2**(i+1)+3)
    for j in range(n):
        if j == 0:
            List = [3*10**(n-1),5*10**(n-1),7*10**(n-1)]
        else:
            for k in range(3**j):
                num = List.pop(0)
                List.append(num+3*10**(n-j-1))
                List.append(num+5*10**(n-j-1))
                List.append(num+7*10**(n-j-1))
    for l in range(len(List)):
        if List[l] <= N:
            s = str(List[l])
            if "3" in s and "5" in s and "7" in s:
                ans += 1

print(ans)

Solution (Python):
import itertools
n = input()
keta = len(list(n))
cnt=0
l = [3,5,7]
for k in range(3,keta+1):
  for i in itertools.product(l, repeat=k):
    if 3 in i and 5 in i and 7 in i:
      tmp=""
      for j in i:
        tmp+=str(j)
      if int(tmp)<=int(n):
        cnt+=1
print(cnt)

Solution (Python):
import itertools

n = int(input())

num = 4**9
ans = 0

for i in range(num):
    num_0 = 0
    num_3 = 0
    num_5 = 0
    num_7 = 0

    s = i
    for m in range(9):
        num_0 += 0 * int(s % 4 == 0) * 10 ** m
        num_3 += 3 * int(s % 4 == 1) * 10 ** m
        num_5 += 5 * int(s % 4 == 2) * 10 ** m
        num_7 += 7 * int(s % 4 == 3) * 10 ** m
        s = s // 4
    
    tmp = num_0 + num_3 + num_5 + num_7
        
    if tmp > n:
        break
    
    tmp = str(tmp)
    
    if num_3 > 0 and num_5 > 0 and num_7 > 0 and tmp.count('0') == 0:
        
        ans += 1

print(ans)

Solution (Python):
import itertools as it
N=int(input())
d=0
for i in range(3,10):
    for c in sorted(list(it.product('753',repeat=i))):
        if int(''.join(c))>N:
            print(d)
            exit(0)
        if len(set(c))==3:d+=1
print(d)

Solution (Python):


import itertools

def get_list(N, rep):
    count = 0
    a = list(itertools.product([3, 5, 7], repeat=rep))
    delList = []
    for e in a:
        if 3 not in e or 5 not in e or 7 not in e:
            delList.append(e)
    for e in delList:
        a.remove(e)
    for e in a:
        val = 0
        for i in range(rep):
            val += e[i] * 10**(rep-i-1)
        if val <= N:
            count += 1
    return count

def resolve():
    N = int(input())
    ans = 0
    for i in range(9):
        ans += get_list(N, i+1)
    print(ans)


if __name__ == "__main__":
    resolve()

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

def count_753(s):
    if int(s) > n:
        return 0
    ret = all((c in s for c in '753'))
    for c in '753':
        ret += count_753(s + c)
    return ret

print(count_753('0'))

Solution (Python):
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    N_STR = inputs[0]
    N = int(N_STR)

    if len(N_STR) <= 2:
        return 0

    def check_over(string):
        if int(string) > N:
            return False
        return True

    def check_all_appered(string):
        does_appered = {
            '3': False,
            '5': False,
            '7': False
        }

        for s in string:
            if s in does_appered:
                does_appered[s] = True
        are_all_true = True
        for d in does_appered.values():
            are_all_true = are_all_true and d
        return are_all_true

    def create_s(origin, until_len):
        if len(origin) == until_len:
            return [origin]

        ret = []
        ret += create_s(origin+'3', until_len)
        ret += create_s(origin+'5', until_len)
        ret += create_s(origin+'7', until_len)

        pop_items = []
        for i in range(0, len(ret)):
            if ret[i] is None \
                    or not check_all_appered(ret[i]) \
                    or not check_over(ret[i]):
                pop_items.append(i)
        for p in reversed(pop_items):
            ret.pop(p)

        return ret

    ret = []
    for i in range(3, len(N_STR)+1):
        ret += create_s('', i)
    return len(ret)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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

def dp(now) :
    if int(now) > N :
        return 0
    count = 0
    if all(x in now for x in ['7', '5', '3']) :
        count += 1
    for x in ['7', '5', '3'] :
        count += dp(now + x)
    return count

ans = dp('0')
print(ans)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    n = II()
    a = [7,5,3]
    if n in a:
        print("YES")
    else:
        print("NO")
    return


def B():
    s = S()
    ans = inf
    for i in range(len(s) - 2):
        ans = min(ans, abs(753-int("".join(s[i:i + 3]))))
    print(ans)
    return


def C():
    s = II()
    n = len(str(s))
    ans = 0
    for i in range(3,n+1):
        c = itertools.product(["3", "5", "7"], repeat=i)
        for ci in c:
            if len(set(ci)) < 3:
                continue
            if int("".join(ci)) <= s:
                ans += 1
    print(ans)

        
    return


def D():
    return


if __name__ == '__main__':
    C()

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

def f(s):

    if int(s) > n:
        return 0

    if set(list(s)) == {"0", "3", "5", "7"}:
        ans = 1
    else:
        ans = 0

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

    return ans

print(f("0"))

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

def dfs(s):

    if int(s) > N:
        return 0
        
    if set(list(s)) == {"7", "5", "3", "0"}:
        ret = 1
    else:
        ret = 0

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

    return ret

print(dfs('0'))

Solution (Python):
def f(N, D, b=False):
    if len(N)==0: return 0 if b else 1

    n0 = int(N[0])
    m = 0
    for d in D:
        if d==n0:
            m += f(N[1:], D)
        if d<n0:
            m += len(D)**len(N[1:])
    return m + f('9'*len(N[1:]), D, True) if b else m

N = input()
print(( f(N,[3,5,7],True)
       -f(N,[3,5  ],True)
       -f(N,[  5,7],True)
       -f(N,[3,  7],True)
       +f(N,[3    ],True)
       +f(N,[  5  ],True)
       +f(N,[    7],True)))

Solution (Python):
from math import log10, floor
import bisect


N = int(input())

M = []


def rec(s):
    for x in "357":
        xx = s + x
        if int(xx) >= 2e9:
            break
        if "3" in xx and "5" in xx and "7" in xx:
            M.append(int(xx))
        rec(xx)


rec("")
M.sort()
ans = bisect.bisect_right(M, N)
print(ans)

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())

c = ["!", "3", "5", "7"]
def shichigosan_numbers():
    x = 0
    while True:
        x += 1
        s = ""
        y = x
        while y > 0:
            s = c[y%4] + s
            y = y // 4
        if "!" not in s and "3" in s and "5" in s and "7" in s: 
            yield int(s)

ans = 0
for x in shichigosan_numbers():
    if x <= n:
        ans += 1
    else: 
        print(ans)
        exit()

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

def shitigosan(x):
  if int(x) > N:
    return 0
  cnt = 1 if all(x.count(c) > 0 for c in '753') else 0
  for i in "753":
    cnt += shitigosan(x+i)
  return cnt
  
print(shitigosan("0"))

Solution (Python):
def generate357(num_str,n):  
  if len(num_str) < 3:
    pass
  elif int(num_str) > n:    
    return 0
  
  count = sum([generate357(str(i) + num_str, n) for i in '357'])      
  
  if all((s in num_str)  for s in '357'):
    count +=1
  return count   

n = int(input())
print(generate357('',n))

Solution (Python):
n = int(input())
m = ["3","5","7"]
m1 = m.copy()
for i in range(2,10):
    mi = []
    for x in m1:
        mi.append(x+"3")
        mi.append(x+"5")
        mi.append(x+"7")
    m += mi
    m1 = mi
count = 0
for x in m:
    if int(x)<= n and x.count("3")*x.count("5")*x.count("7") != 0:
        count += 1
print(count)

Solution (Python):
import math
n = input()
ans = 0
li=[]
global num_li
num_li = []
def create_num(n, length):
    global num_li
    if len(n) == length:
        num_li.append(n)
    else:
        create_num(n+"3", length)
        create_num(n+"5", length)
        create_num(n+"7", length)
for i in range(1, len(n)+1):
    if i == len(n):
        create_num("", i)
        for j in num_li:
            if "3" in j and "5" in j and "7" in j and int(j) <= int(n):
                ans+= 1       
    elif i > 2:
        ans += 3**i - (2**i -2) * 3 - 3 
print(ans)

Solution (Python):
x=input()
n=len(x)

res=[]

import numpy as np
import itertools

x753=[3,5,7]

pt=list(itertools.product(x753, repeat=n))

pt_n=len(pt)

for i in range(pt_n):
	y="".join(map(str, pt[i]))
	for j in range(n):
		z=y[j:]
		if int(z)<=int(x) and ('3' in z) and ('5' in z) and ('7' in z):
			res.append(z)
            
print(len(set(res)))

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):
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(v) <= N:
            ans += 1
print(ans)

Solution (Python):
n = input()
def dfs(s):
    if int(s) > int(n):
        return 0
    ret = 1 if all(c in s for c in ['7', '5', '3']) else 0
    for c in ['7', '5', '3']:
        ret += dfs(s + c)
    return ret
print(dfs('0'))

Solution (Python):
from itertools import *

N = int(input())

A = ["3", "5", "7"]

ans = 0

length = len(str(N))

for i in range(3, length+1) :
    for prod in product(A, repeat=i) :
        if prod.count("3") == 0 or prod.count("5") == 0 or prod.count("7") == 0 :
            continue
        
        num = int("".join(prod))
        if num > N :
            break
        
        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) for c in '753') else 0
    for c in '753':
        ret += dfs(s + c)
    return ret

print(dfs('0'))

Solution (Python):
N = input()
L = len(N)
NUM = int(N)

count = 0
for l in range(1, L):
        count += 3**l - 3*2**l + 3
q = '3'*L
while True:
        if int(q) > NUM:
                break
        if q.count('3') > 0 and q.count('5') > 0 and q.count('7') > 0:
                count += 1
        if q == '7'*(L-2) + '5' + '3':
                break
        for i in range(1, L+1):
                k = q[-i]
                if k == '3':
                        next = q[:-i] + '5' + '3'*(i-1)
                        break
                elif k == '5':
                        next = q[:-i] + '7' + '3'*(i-1)
                        break
        q = next

print(count)

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

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 = int(input())
n = len(str(N))
lst = [3, 5, 7]

def calc(count, tmp):
    ans = 0
    if count >= 9:
        return 0
    for i in lst:
        tmp += i * (10 ** count)
        
        if tmp <= N:
            
            if  '7' in str(tmp) and '5' in str(tmp) and '3' in str(tmp):
                ans += 1
        ans += calc(count + 1 ,tmp)
        tmp -= i * (10 ** count)
    return ans

ans = calc(0, 0)
print (ans)

Solution (Python):
def sub753(K, lst):
    if K == 1:
        return ['3', '5', '7']
    ans = [pre + suf for suf in sub753(K - 1, lst) for pre in '357']
    lst.extend(ans)
    return ans


N = int(input())

lst = list()
sub753(10, lst)

cnt = 0
for num in lst:
    if '3' in num and '5' in num and '7' in num and int(num) <= N:
        cnt += 1
print(cnt)

Solution (Python):
def ac(s, t, int3, int5, int7):
    if s == "":
        return ac(s + "3", t, int3 + 1, int5, int7) \
               + ac(s + "5", t, int3, int5+1, int7) \
               + ac(s + "7", t, int3, int5, int7+1)
    elif int(s) <= t:
        if int3 != 0 and int5 != 0 and int7 != 0:
            return 1 \
                   + ac(s + "3", t, int3 + 1, int5, int7) \
                   + ac(s + "5", t, int3, int5+1, int7) \
                   + ac(s + "7", t, int3, int5, int7+1)
        else:
            return 0 \
                   + ac(s + "3", t, int3 + 1, int5, int7) \
                   + ac(s + "5", t, int3, int5 + 1, int7) \
                   + ac(s + "7", t, int3, int5, int7 + 1)
    else:
        return 0


a = int(input())
print(ac("", a, 0, 0, 0))

Solution (Python):
num753 = ['7', '5', '3']
N = int(input())
cnt = 0
for i in range(3, len(str(N))+1):
	for j in range(0, 3**i):
		m = j
		exists = [False, False, False]
		num = ''
		for k in range(0, i):
			num = num + num753[m%3]
			exists[m%3] = True
			m //= 3
		if False not in exists and int(num) <= N:
			cnt += 1
print(cnt)

Solution (Python):
N = input()

def dfs(m):
    ans = 0
    if len(set(m)) == 3 and int(m) <= int(N):
        ans += 1

    if len(m) < len(N):
        for c in ['3', '5', '7']:
            ans += dfs(m + c)

    return ans

print(dfs(""))

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

def search(keta, num):
  if keta == 0:
    if '0' in str(int(num)):
      return 0
    elif '3' in num and '5' in num and '7' in num:
      if int(num) <= N:
        return 1
      else:
        return 0
    else:
      return 0
  else:
    return search(keta-1, num + '0') + search(keta-1, num + '3') + search(keta-1, num + '5') + search(keta-1, num + '7')

keta = len(str(N))

ans = search(keta, '')
print(ans)

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

def search(s) :
    if int(s) > N :
        return 0
    ret = 1 if all(s.count(i) > 0 for i in ['7', '5', '3']) else 0  
    for c in ['7', '5', '3'] :
        ret += search(s + c)
    return ret

ans = search('0')

print(ans)

Solution (Python):


N=int(input())

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

print(check('0'))

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

def count(sc):
    c3 = 0
    c5 = 0
    c7 = 0
    for c in sc:
        if c == "3":
            c3 += 1
        elif c == "5":
            c5 += 1
        elif c == "7":
            c7 += 1
        else:
            raise ValueError("error!")
    return c3 > 0 and c5 > 0 and c7 > 0
            

def up(tsc):
    res = ['0']*(len(tsc)+1)
    done = False
    i = len(tsc) - 1
    while not done and i >= -1:
        if tsc[i] == '7':
            carry = True
            res[i+1] = '3'
        elif tsc[i] == '5':
            res[i+1] = "7"
            done = True
        elif tsc[i] == '3':
            res[i+1] = "5"
            done = True
        elif i == -1:
            res[i+1] == '3'
            done = True
        i -= 1
    for i in range(i, -1, -1):
        res[i+1] = tsc[i]
    if res[0] == "0":
        return "".join(res[1:])
    else:
        return "".join(res)
        
def solve(n):
    tsc = "357"
    res = 0
    while int(tsc) <= n:
        if count(tsc):
            res += 1
        tsc = up(tsc)
    return res
print solve(n)

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

def solve(now,seven,five,three):
    if now > n:
        return 0
    if min(seven,five,three) != 0:
        cnt = 1
    else:
        cnt = 0
    cnt += solve(now*10+3,seven,five,three+1)
    cnt += solve(now*10+5,seven,five+1,three)
    cnt += solve(now*10+7,seven+1,five,three)

    return cnt
print(solve(0,0,0,0))

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

if __name__ == "__main__":
    n = int(input())
    print(check753('0'))

Solution (Python):
import numpy as np

n = input()
r = len(n)
n = int(n)
kouho = []
pre = [""]

for i in range(r):
    pro = []
    for temp in pre:
        kouho.append(temp+"3")
        kouho.append(temp+"5")
        kouho.append(temp+"7")
        pro.append(temp+"3")
        pro.append(temp+"5")
        pro.append(temp+"7")
    pre = pro

def ctit(s):
    a = 0
    b = 0
    d = 0
    for c in s:
        if c == "3":
            a += 1
        elif c == "5":
            b += 1
        else:
            d += 1
    if a > 0 and b > 0 and d > 0:
        return True
    else:
        return False

ans = 0
for temp in kouho:
    if int(temp) <= n:
        if ctit(temp):
            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())
stack = [3, 5, 7]
counter = 0
def check753(i):
	s = str(i)
	
	if s.count('3') >= 1 and s.count('5') >= 1 and s.count('7') >= 1:
		return 1
	else:
		return 0

while stack:
	now_node = stack.pop()
	for i in [3, 5, 7]:
		next_node = now_node * 10 + i
		if next_node <= N:
			counter += check753(next_node)
			stack.append(next_node)

print(counter)