CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))

cnt = 0
i = 1
while i <= n:
    is_broken = False
    string = list(str(i))
    for j, s in enumerate(string):
        if s not in ['3', '5', '7']:
            i = i + 10**(len(string) - j - 1)
            is_broken = True
            break
    if is_broken:
        continue

    c1 = string.count('3') >= 1
    c2 = string.count('5') >= 1
    c3 = string.count('7') >= 1
    if c1 and c2 and c3:
        cnt += 1

    i += 1

print(cnt)

# Optimized solution
n = int(eval(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')))
# Original solution
n = int(eval(input()))
def dfs(x):
    if int(x) > n:
        return 0
    
    if all(x.count(i) > 0 for i in "753"):
        ret = 1
    else:
        ret = 0
    
    for i in "753":
        ret += dfs(x+i)
        
    return ret
print((dfs("0")))

# Optimized solution
n = int(eval(input()))

count = 0
def dfs(x):
    global count
    if int(x) > n:
        return 0
    
    for i in ('753'):
        dfs(x+i)
    
    check =  True
    for j in ('753'):
        if x.find(j) == -1:
            check = False
    if check:
        count += 1
        
    return count
print((dfs('0')))
# Original solution
N = int(eval(input()))
from collections import deque

def solve(N):
    ans = 0
    d = deque([3,5,7])
    n = d.popleft()
    while n<=N:
        if len(set(list(str(n))))==3:
            ans += 1
        for num in [3,5,7]:
            new = int(str(n)+str(num))
            d.append(new)
        n = d.popleft()
    return ans
print((solve(N)))

# Optimized solution
from collections import deque
def solve():
    N = int(eval(input()))
    ans = 0
    d = deque([3,5,7])
    while len(d):
        n = d.popleft()
        for i in range(3,8,2):
            a = n*10+i
            if a<=N:
                if len(set(list(str(a))))==3:
                    ans += 1
                d.append(a)
    return ans
print((solve()))
# Original solution
from itertools import product
n = int(eval(input()))
a = ['7','5','3']

x =[]
for i in range(3,11):
    x += list(product(a, repeat = i))
y = []
for j in x:
    if '7' in j and '5' in j and '3' in j:
        y.append(j)
z = []
for k in range(len(y)):
    z.append(''.join(y[k]))
z = [int(_) for _ in z]

b = 0
for p in z:
    if p <= n:
        b += 1

print(b)


# Optimized solution
from itertools import product
l = []
for _ in range(3,10):
    tmp = list(product('753', repeat = _))
    l += tmp

m = []
for i in l:
    if len(set(i)) == 3:
       m.append(int(''.join(i)))

n = int(eval(input()))
ans = 0
for j in m:
    if j <= n:
        ans += 1

print(ans)
# Original solution
# ＢＦＳ, パターン列挙_全探索用

from collections import deque

n = int(eval(input()))

# DFS_start
queue = deque([0]) # 初期化_ここでは'0'を設置
pre_ans = [] # パターン候補の器_初期化

while queue: # queueが空になるまでループ
    tmp = queue.popleft() # パターンの候補を popleft
    if tmp <= n: # パターンとしての条件を確認
        pre_ans.append(tmp) # 条件に合えば append
        x = tmp * 10 + 3 # パターンの候補を作成して...
        y = tmp * 10 + 5 # 〃
        z = tmp * 10 + 7 # 〃
        queue += [x, y, z]  # 積む
# DFS_end

ans = 0
for i in pre_ans: # 列挙したパターンを全探索
    if len(set(str(i))) == 3:
        ans += 1

print(ans)

'''
上記は パターンを列挙 → 全探索 だが、
実際には パターンを列挙 しながら 探索 が高効率

from collections import deque

n = int(input())

# DFS_start
queue = deque([0]) # 初期化_ここでは'0'を設置

ans = 0
while queue: # queueが空になるまでループ
    tmp = queue.popleft() # パターンの候補を popleft
    if tmp <= n: # パターンとしての条件を確認
        if len(set(str(tmp))) == 3: # ここで ansを探索
            ans += 1
        x = tmp * 10 + 3 # パターンの候補を作成して...
        y = tmp * 10 + 5 # 〃
        z = tmp * 10 + 7 # 〃
        queue += [x, y, z]  # 積む

print(ans)

'''

# Optimized solution
# ＤＦＳ, パターン列挙_全探索用

n = int(eval(input()))

# DFS_start
stack = [0] # 初期化_ここでは'0'を設置
pre_ans = [] # パターン候補の器_初期化

while stack: # stackが空になるまでループ
    tmp = stack.pop() # パターンの候補を pop
    if tmp <= n: # パターンとしての条件を確認
        pre_ans.append(tmp) # 条件に合えば append
        x = tmp * 10 + 3 # パターンの候補を作成して...
        y = tmp * 10 + 5 # 〃
        z = tmp * 10 + 7 # 〃
        stack += [x, y, z]  # 積む
# DFS_end

ans = 0
for i in pre_ans: # 列挙したパターンを全探索
    if len(set(str(i))) == 3:
        ans += 1

print(ans)


'''
上記は パターンを列挙 → 全探索 だが、
実際には パターンを列挙 しながら 探索 が高効率

n = int(input())

stack = [0]
ans = 0
while stack:
    tmp = stack.pop()
    if tmp <= n:
        if len(set(str(tmp))) == 3:
            ans += 1
        x = tmp * 10 + 3
        y = tmp * 10 + 5
        z = tmp * 10 + 7
        stack += [x, y, z]

print(ans)

'''
# Original solution
from functools import reduce
n = int(eval(input()))

ans = 0
def dfs(numl):
    global ans
    if 3 in numl and 5 in numl and 7 in numl and n >= reduce( lambda a,b:10*a+b, numl):
        ans += 1
    if len(str(n)) > len(numl):
        for i in [3,5,7]:
            dfs(numl+[i])

dfs([])
print(ans)

# Optimized solution
n = int(eval(input()))

global ans
ans = 0

def dfs(s):
    global ans
    if s:
        if int(s) > n:
            return
    if s:
        if "3" in s and "5" in s and "7" in s:
            ans += 1
    dfs(s + "3")
    dfs(s + "5")
    dfs(s + "7")

dfs("")


print(ans)
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


n = int(readline())


def dfs(s):
    if int(s) > n:
        return 0
    flag = True
    for check in '753':
        if s.count(check) <= 0:
            flag = False
    if flag:
        x = 1
    else:
        x = 0
    for check in '753':
        x += dfs(s + check)
    return x


print((dfs('0')))


# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
cnt = 0
q = ['3', '5', '7']
while q:
    qq = q.pop()
    v = list(qq)
    if '3' in v and '5' in v and '7' in v:
        cnt += 1
    if int(qq + '3') <= n:
        q.append(qq + '3')
        if int(qq + '5') <= n:
            q.append(qq + '5')
            if int(qq + '7') <= n:
                q.append(qq + '7')
print(cnt)
# Original solution
import itertools
n = int(eval(input()))
a = [0, 3, 5, 7]
ans = []
res = 0
for i in itertools.product(a, repeat = 9):
    val = 0
    for j in range(len(i)):
        val += 10 ** j * i[j]
    # print(val)
    tmp = str(val)
    if val <= n and len(set(tmp)) == 3 and "0" not in tmp:
        res += 1
        ans.append(val)

ans.sort()
print(res)
# print(ans)

# Optimized solution
import itertools

n = int(eval(input()))
list_3_5_7 = ["3", "5", "7"]

res = 0
for i in range(3, 10):
    tmp_product_list = list(itertools.product(list_3_5_7, repeat = i))
    for tmp_list in tmp_product_list:
        tmp_str = "".join(tmp_list)
        if len(set(tmp_str)) == 3 and int(tmp_str) <= n:
            res += 1

print(res)
# Original solution
import typing
n = int(eval(input()))

res = set()
str_num = ""
def dfs(str_num:str, i:int):
    global res
    if i == 10 :
        # print(str_num)
        if str_num and int(str_num) <= n and len(set(str_num)) == 3:
            res.add(str_num)
            # print(res, str_num)
        return 0
    dfs(str_num + "3", i + 1)
    dfs(str_num + "5", i + 1)
    dfs(str_num + "7", i + 1)
    dfs(str_num      , i + 1)

if __name__ == "__main__":
    dfs(str_num, 0)
    print((len(res)))


# Optimized solution
import typing
n = int(eval(input()))

res = 0
str_num = ""


def dfs(str_num: str, i: int, finish:int):
    global res
    if i == finish:
        # print(str_num)
        if str_num and int(str_num) <= n and len(set(str_num)) == 3:
            res += 1
            # print(res, str_num)
        return 0
    dfs(str_num + "3", i + 1, finish)
    dfs(str_num + "5", i + 1, finish)
    dfs(str_num + "7", i + 1, finish)
    # dfs(str_num, i + 1)


if __name__ == "__main__":
    for i in range(3, 10):
        dfs(str_num, 0, i)
    print(res)
# Original solution
N = int(eval(input()))
T = ("3","5","7")

from collections import deque
que = deque(list(T))

ans = 0
while que:
  num = que.pop()
  if int(num) > N:
    continue
  if len(set(num)) == 3:
    ans += 1
  for t in T:
    que.append(num + t)

print(ans)

# Optimized solution
N = int(eval(input()))
T = ("3","5","7")

def dfs(x):
  if x != "" and int(x) > N:
    return 0
  res = 0
  if len(set(x)) == 3:
    res = 1
  for t in T:
    res += dfs(x + t)
  return res
  
print((dfs("")))
# Original solution
import itertools
import bisect

lis = list(itertools.product('7530',repeat = 9))
int_lis = list(map(int,list(map(''.join,lis))))
str_lis = list(map(str,int_lis[:-16]))
lis = []
for s in str_lis:
    if ('7' in s) and ('5' in s) and ('3' in s) and ('0' not in s) :
        lis.append(int(s))
print((bisect.bisect_right(sorted(lis),int(eval(input())))))


# Optimized solution
import itertools,bisect

num_list = []
def toInt(arr):
    num = int(''.join(arr))
for i in range(3,10):
    num_list += list(itertools.product('753',repeat=i) )
num = []
for nm in num_list:
    if '3' in nm and '5' in nm and '7' in nm:
        num.append(int(''.join(nm)))
num.sort()

print((bisect.bisect_right(num,int(eval(input())))))
# Original solution
N = int(eval(input()))

dp = []

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

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

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


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

# Optimized solution
N = int(eval(input()))
dp = []

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

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

dfs(0)
print((len([item for item in dp if item <= N])))
# Original solution
N = int(eval(input()))
dp = []

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

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

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


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

print((len([num for num in memo if num <= N])))
# Original solution
from collections import deque
from collections import Counter
n=int(eval(input()))
if n<357:
    print((0))
    exit()
i=357
ans=0
while i<=n:
  c=Counter(str(i))
  if '3' in c and '5' in c and '7' in c:
    if c['3']+c['5']+c['7']==len(str(i)):
      ans+=1
  a=list(map(int,list(str(i))))
  a[-1]+=2
  j=-1
  while a[j]>7 and -j<len(a):
    a[j]=3
    a[j-1]+=2
    j-=1
  if a[0]>7:
    a[0]=33
  i=int(''.join(map(str,a)))

print(ans)


# Optimized solution
n=int(eval(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')))
# Original solution
N = int(eval(input()))


def dfs(s):  # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0  # s 自体が七五三数なら+1
    for c in '753':
        ret += dfs(s + c)
    return ret


print((dfs('0')))  # 本当はdfs('')と書きたいがint(s)でエラーを吐かないように仕方なく


# Optimized solution
N = int(eval(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'])
# print(num_list)
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)
# Original solution
#解説AC,9割写経
n = int(eval(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")))


# Optimized solution
def dfs(n,a,s):
    global ans
    temp = int(s)
    if temp > n:
        return
    if "7" in s and "5" in s and "3" in s and n>=temp:
        ans += 1
    for i in a:
        dfs(n,a,s+i)
ans = 0
a = ["7","5","3"]
n = int(eval(input()))
s = "0"
dfs(n,a,s)
print(ans)
# Original solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools #list(accumulate(A))
from collections import deque

N = ii()
que = deque([33, 35, 37, 53, 55, 57, 73, 75, 77])
ele = ['3', '5', '7']

ind = 0
while True:
    num = que[ind] * 10
    que.append(num + 3)
    que.append(num + 5)
    que.append(num + 7)
    if len(str(num)) >= 10:
        break
    ind += 1

ind = bisect.bisect_right(que, N)

ele = ['3', '5', '7']
cnt = 0
for i in range(ind):
    tmp = str(que[i])
    for e in ele:
        if e not in tmp:
            cnt += 1
            break

print((ind - cnt))

# Optimized solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools #list(accumulate(A))
from collections import deque

N = ii()
ele = [3, 5, 7]
l = []

def dfs(num, flag3, flag5, flag7):
    #print(num, flag3, flag5, flag7)
    if num > N:
        return 
    if flag3 is flag5 is flag7 is True:
        l.append(num)
    num *= 10
    dfs(num+3, True, flag5, flag7)
    dfs(num+5, flag3, True, flag7)
    dfs(num+7, flag3, flag5, True)

dfs(0, False, False, False)
print((len(l)))
# Original solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools #list(accumulate(A))

N = ii()
l = []

for keta in range(3, 10):
    for koho in itertools.product(['3', '5', '7'], repeat=keta):
        l.append(int(''.join(koho)))

l.sort()

ele = ['3', '5', '7']
cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ele):
        cnt += 1

print(cnt)

# Optimized solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#import itertools #list(accumulate(A))
#from collections import deque

## FlagをもたせたDFS

N = ii()
ele = [3, 5, 7]
l = []

def dfs(num, flag):
    if num > N:
        return 
    if flag == 7:
        l.append(num)
    num *= 10
    for i, e in enumerate(ele):
        dfs(num+e, flag | 1<<i)

dfs(0, 0)
print((len(l)))
# Original solution
# coding:utf-8

import sys


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


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


N = int(eval(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')))


# Optimized solution
# coding:utf-8

import itertools

N = int(eval(input()))

ans = 0
for i in range(2, len(str(N))):
    for s in itertools.product('753', repeat=i+1):
        if int(''.join(s)) > N:
            continue
        if all(s.count(c) > 0 for c in '753'):
            ans += 1

print(ans)
# Original solution
from itertools import *
N = int(eval(input()))
ans = 0

for i in product("0357",repeat=10):
  j = "".join(i)
  if "0" not in str(int(j)) and "3" in j and "5" in j and "7" in j and int(j)<=N:
    ans+=1

print(ans)

# Optimized solution
from itertools import *
N = int(eval(input()))
S = []
ans = 0

for n in range(10):
  S+=list(product("357",repeat=n))

for s in S:
  if len(set(s))==3 and int("".join(s))<=N:
    ans+=1

print(ans)
# Original solution
N = int(eval(input()))
from itertools import product
ans = 0
for n in range(3,10):
    for ptn in product('753', repeat=n):
        if '7' not in ptn: continue
        if '5' not in ptn: continue
        if '3' not in ptn: continue
        v = int(''.join(ptn))
        if v <= N:
            ans += 1
print(ans)

# Optimized solution
N = int(eval(input()))
ans = 0
import itertools
for i in range(1,10):
    for ptn in itertools.product('753',repeat=i):
        s = ''.join(ptn)
        if int(s) > N: continue
        if '3' not in s: continue
        if '5' not in s: continue
        if '7' not in s: continue
        ans += 1
print(ans)
# Original solution
# -*- coding: utf-8 -*-
"""
C - 755

"""
def gen_357():
    def conv(n):
        res = []
        while n:
            n, r = divmod(n, 4)
            res.append(str(str(r)))
        if not res:
            res = ['0']
        return ''.join(res[::-1]).translate(str.maketrans('0123', '0357'))

    n = 0
    while True:
        t = conv(n)
        while '0' in t or len(set(list(t))) != 3:
            n += 1
            t = conv(n)
        yield t
        n += 1


def solve(n):
    ans = 0
    g = gen_357()
    while True:
        t = next(g)
        if int(t) > n:
            break
        ans += 1
    return ans


n = int(eval(input()))
ans = solve(n)
print(ans)


# Optimized solution
# -*- coding: utf-8 -*-
"""
C - 755
TLE
"""
def gen_357():
    def conv(n):
        res = []
        while n:
            n, r = divmod(n, 4)
            if r == 0 and n:
                return '0'
            res.append(str(str(r)))
        if not res:
            res = ['0']
        return ''.join(res[::-1]).translate(str.maketrans('0123', '0357'))

    n = 0
    while True:
        t = conv(n)
        while '0' in t or len(set(list(t))) != 3:
            n += 1
            t = conv(n)
        yield t
        n += 1


def solve(n):
    ans = 0
    g = gen_357()
    while True:
        t = next(g)
        if int(t) > n:
            break
        ans += 1
    return ans


n = int(eval(input()))
ans = solve(n)
print(ans)
# Original solution
n = int(eval(input()))
sitigosan_list = [3, 5, 7]
count = 0

if n < 357:
    print((0))
    exit()

def make_753(num):
    b = str(num) + '3'
    c = str(num) + '5'
    d = str(num) + '7'
    sitigosan_list.append(int(b))
    sitigosan_list.append(int(c))
    sitigosan_list.append(int(d))


for i in sitigosan_list:
    make_753(i)
    if max(sitigosan_list) > n:
        break

for j in sitigosan_list:
    if '3' in str(j) and '5' in str(j) and '7' in str(j) and j <= n:
        count += 1

print(count)


# Optimized solution
n = int(eval(input()))

sitigosan_list = [3, 5, 7]
count = 0

if n < 357:
    print((0))
    exit()

def make_753(num):
    global count
    b = str(num) + '3'
    c = str(num) + '5'
    d = str(num) + '7'
    if int(b) > n:
        return
    elif '3' in str(b) and '5' in str(b) and '7' in str(b):
        count += 1
        make_753(b)
    else:
        make_753(b)
    if int(c) > n:
        return
    elif '3' in str(c) and '5' in str(c) and '7' in str(c):
        count += 1
        make_753(c)
    else:
        make_753(c)
    if int(d) > n:
        return
    elif '3' in str(d) and '5' in str(d) and '7' in str(d):
        count += 1
        make_753(d)
    else:
        make_753(d)


make_753('')

print(count)
# Original solution
from itertools import product
n = int(eval(input()))
A = set()
for x in product('753_', repeat=9):
    s = ''.join(x).replace('_', '')
    if all(d in s for d in '753') and int(s) <= n:
        A.add(s)
print((len(A)))

# Optimized solution
n = int(eval(input()))
B = []
def dfs(A):
  x = int(''.join(A))
  if x <= n:
    if '7' in A and '5' in A and '3' in A:
      B.append(x)
    dfs(A + ['7'])
    dfs(A + ['5'])
    dfs(A + ['3'])

dfs(['0'])
print((len(B)))
# Original solution
N = int(eval(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")))

# Optimized solution
import itertools

N = int(eval(input()))
ans = 0

for i in range(3, len(str(N)) + 1):
    cand = list(["".join(x) for x in itertools.product("357", repeat=i)])
    for c in cand:
        if int(c) > N:
            continue
        elif all(c.count(s) > 0 for s in "357"):
            ans += 1

print(ans)
# Original solution
n = int(eval(input()))

def squ(x):
    if x == 0:
        return '0'
    a = ""
    while x != 0:
        x, mod = divmod(x, 4)
        a += str(mod)
    return a[::-1]


ans = 0

for x in range(10**6):
    x_squ = squ(x)
    x_str = x_squ.replace('3', '7').replace('2', '5').replace('1', '3')

    if "0" in x_str:
        continue

    if int(x_str) > n:
        break

    if len(set(x_str)) != 3:
        continue

    ans += 1

print(ans)


# Optimized solution
N = int(eval(input()))

def dfs(x):
    if int('0'+x) > N:
        return 0

    retval = 1 if len(set(x)) == 3 else 0
    for c in '753':
        retval += dfs(x + c)
    return retval


print((dfs('')))
# Original solution
N = int(eval(input()))

def dfs(x):
    if int('0'+x) > N:
        return 0

    retval = 1 if len(set(x)) == 3 else 0
    for c in '753':
        retval += dfs(x + c)
    return retval


print((dfs('')))

# Optimized solution
n = int(eval(input()))
like_753 = []


def dfs(x):
    if n < x:
        return 0
    else:
        like_753.append(x)
        dfs(10*x+3)
        dfs(10*x+5)
        dfs(10*x+7)


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

ls_753 = [x for x in like_753 if len(set(str(x))) == 3]
print((len(ls_753)))