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

if keta <= 2:
    print((0))
else:
    # keta-1までのパターン
    ans = 0
    # for k in range(3, keta):
    #    ans = pow(3, k) - 3 - (3*(pow(2, k) + 2))

    from itertools import product
    for k in range(3, keta+1):
        for l in product(['3', '5', '7'], repeat=k):
            if not '3' in l or not '5' in l or not '7' in l:
                continue
            nn = int(''.join(l))
            if nn <= n:
                ans += 1

    print(ans)


# Optimized solution
n = int(eval(input()))
keta = len(str(n))

if keta <= 2:
    print((0))
else:
    # keta-1までのパターン
    ans = 0
    for k in range(3, keta):
        ans += pow(3, k) - 3 - (3*(pow(2, k) - 2))

    from itertools import product
    for l in product(['3', '5', '7'], repeat=keta):
        if not '3' in l or not '5' in l or not '7' in l:
            continue
        nn = int(''.join(l))
        if nn <= n:
            ans += 1

    print(ans)
# Original solution
N = int(eval(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  # 753数
    for c in ['7', '5', '3'] :
        ret += search(s + c)
    return ret

ans = search('0')

print(ans)

# Optimized solution
N = int(eval(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)
# Original solution
import itertools
from sys import stdin
N=int(stdin.readline().rstrip())
ans=0
for i in range(3,11):
    for j in list(itertools.product("753",repeat=i)):
        if int("".join(j)) <= N and len(set("".join(j)))==3:
            ans+=1
print(ans)

# Optimized solution
import itertools
from sys import stdin
N=int(stdin.readline().rstrip())
ans=0
for i in range(3,10):
    for j in list(itertools.product("753",repeat=i)):
        if int("".join(j)) <= N and len(set("".join(j)))==3:
            ans+=1
print(ans)
# Original solution
import sys
import math
import itertools


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(eval(input()))

    A = int(math.log10(N))
    flag=0
    count =0
    for a in range(3,A+2):

        for i in itertools.product([3,5,7],repeat=a):
            digit=0
            if 3 in i and  5 in i and 7 in i:


                for s in range(a):
                    digit+=10**(a-s-1)*i[s]
                if digit <=N:
                    count+=1
                else:
                    break
    print(count)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
import math
import itertools


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    list = [[3, 5, 7]]
    N=int(eval(input()))
    for i in range(9):
        new = []
        for j in list[-1]:
            a = 10 * j
            new.append(a + 3)
            new.append(a + 5)
            new.append(a + 7)
        list.append(new)

    pass
    count =0
    for sub in list:
        for j in sub:
            s =str(j)
            if j>N:
                print(count)
                exit()
            if "3" in s and "7" in s and "5" in s:
                count +=1






if __name__ == "__main__":
    main()
# Original solution
import sys

sys.setrecursionlimit(10 ** 9)
N = int(eval(input()))
length = len(str(N)) + 1
result = []


def dfs(now):
    if len(now) <= length and now != "":
        result.append(now)
        if len(now) == length:
            return
    dfs("3" + now)
    dfs("5" + now)
    dfs("7" + now)


dfs("")
ans = 0
result = set(result)
for r in result:
    i = int(r)
    if i <= N and r.count("3") > 0 and r.count("5") > 0 and r.count("7") > 0:
        ans += 1
print(ans)


# Optimized solution
N = int(eval(input()))
nums = []
length = len(str(N))
def dfs(s, n):
        global nums
        nums.append(s)
        if n == length:
                return
        dfs(s + "3", n + 1)
        dfs(s + "5", n + 1)
        dfs(s + "7", n + 1)

dfs("", 0)
ans = 0
for i in nums:
        if i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1:
                if int(i) <= N:
                        ans += 1
print(ans)
# Original solution
n=int(eval(input()))
alist=[]
import itertools
for i in range(3,10):
  blist=itertools.product(['3','5','7'], repeat=i)
  for j in blist:
    if '3' in j and '5' in j and '7' in j:
      alist.append(int(''.join(j)))
ans=0
for i in alist:
  if i<=n:
    ans+=1
print(ans)

# Optimized solution
n=int(eval(input()))
ans=0
import itertools
for i in range(3,10):
  blist=itertools.product(['3','5','7'], repeat=i)
  for j in blist:
    if '3' in j and '5' in j and '7' in j:
      if int(''.join(j))<=n:
        ans+=1
print(ans)
# Original solution
import sys
input = sys.stdin.readline


c = 0
num = 0
def check(n):
	strn = str(n)
	l = [0, 0, 0]
	for c in strn:
		if c == '3':
			l[0] = 1
		elif c == '5':
			l[1] = 1
		elif c == '7':
			l[2] = 1
	return all(l) or False

def gen(n):
	global c
	# print(n)
	if n > num:
		return
	if check(n):
		# print(n)
		c += 1
	for i in [3, 5, 7]:
		k = 10 * n + i
		gen(k)

def main():
	global num
	num = int(input().strip())
	gen(0)
	print(c)

if __name__ == '__main__':
	main()


# Optimized solution
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

ans = 0
c = ['3', '5', '7']
N = 0

def check(l):
    return len(set(l)) == 3

def nummaker(k, n):
    global ans
    if k == 0:
        q = int(''.join(n))
        if q > N:
            print(ans)
            sys.exit(0)
        if check(n):
            ans += 1
        return
    for i in c:
        m = n[:]
        m.append(i)
        nummaker(k-1, m)

def main():
    global N
    N = int(input().strip())
    for i in range(1, 11):
        nummaker(i, [])

if __name__ == '__main__':
    main()
# Original solution
UP = int(1e9)
s = set()
full = set('357')


def dfs(n):
    if n > UP:
        return
    if set(str(n)) == full:
        s.add(n)
    dfs(n * 10 + 3)
    dfs(n * 10 + 5)
    dfs(n * 10 + 7)


dfs(0)
l = list(s)
l.sort()
n = int(eval(input()))
ans = 0
for i in l:
    if i <= n:
        ans += 1
    else:
        break
print(ans)


# Optimized solution
UP = int(1e9)
s = set()


def dfs(n, f3, f5, f7):
    if n > UP:
        return
    if f3 and f5 and f7:
        s.add(n)
    dfs(n * 10 + 3, True, f5, f7)
    dfs(n * 10 + 5, f3, True, f7)
    dfs(n * 10 + 7, f3, f5, True)


dfs(0, False, False, False)
l = list(s)
l.sort()
n = int(eval(input()))
ans = 0
for i in l:
    if i <= n:
        ans += 1
    else:
        break
print(ans)
# Original solution

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
##############################

N = int(eval(input()))

def dfs(next_value, value, count_flag, count):
    value += next_value
    int_value = int(value)

#    print(int_value)

    if int_value > N:
        return count

    if int_value >= 357:
        if count_flag == False:
            if len(set(list(value))) == 3:
                count_flag = True

        if count_flag:
            count += 1

    count = dfs('3', value, count_flag, count)
    count = dfs('5', value, count_flag, count)
    count = dfs('7', value, count_flag, count)

    return count


count = 0
value = ''

count = dfs('3', '', False, count)
count = dfs('5', '', False, count)
count = dfs('7', '', False, count)

print(count)

# Optimized solution


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N = int(eval(input()))

def dfs(X, bit, count):
    if bit == 7:
        if X <= N:
            count += 1

    if X >= N:
        return count


    count = dfs(X*10+7, bit|4, count)
    count = dfs(X*10+5, bit|2, count)
    count = dfs(X*10+3, bit|1, count)

    return count


count = dfs(0, 0, 0)
print(count)
# Original solution
from itertools import product

N = int(eval(input()))

S = str(N)
n = len(S)

ans = 0
for i in range(3, n + 1):
    for p in product(['3', '5', '7'], repeat=i):
        x = int(''.join(p))
        if x <= N and len(set(p) & {'3', '5', '7'}) == 3:
            ans += 1
print(ans)


# Optimized solution
from itertools import product

N = int(eval(input()))

S = [int(x) for x in str(N)]
n = len(S)

# dp[pos][smaller?][started?][3?][5?][7?]
dp = [[[[[[0] * 2 for _ in range(2)] for _ in range(2)]
        for _ in range(2)] for _ in range(2)] for _ in range(n + 1)]
dp[0][0][0][0][0][0] = 1

for i, j, k, c3, c5, c7 in product(list(range(n)), [0, 1], [0, 1], [0, 1], [0, 1],
                                   [0, 1]):
    num = [0, 3, 5, 7]
    if not j:
        num = [x for x in num if x <= S[i]]
    if k:
        num = [x for x in num if x != 0]
    for x in num:
        f0 = k or x != 0
        f3 = c3 or x == 3
        f5 = c5 or x == 5
        f7 = c7 or x == 7
        dp[i + 1][j or x < S[i]][f0][f3][f5][f7] += dp[i][j][k][c3][c5][c7]

ans = sum([dp[n][j][1][1][1][1] for j in [0, 1]])
print(ans)
# Original solution
# 再帰で3,5,7を振り分けるのめんどくさそうだなと思ったら、
# 振り分けずに0個以上あればあればいいセットを作ってそこから省く、という手段を使うのか...

n = int(eval(input()))
sitigosan = []


def f(i):
    if i <= 10 ** 9:
        sitigosan.append(i)
        f(i * 10 + 3)
        f(i * 10 + 5)
        f(i * 10 + 7)


f(3)
f(5)
f(7)
# これだと3から埋めていってダメだと5、7に変えていってるので昇順に並んでない

sitigosan = sorted(sitigosan)
count = 0
for sgs in sitigosan:
    if sgs > n:
        break
    str_sgs = str(sgs)
    if "3" in str_sgs and "5" in str_sgs and "7" in str_sgs:
        count += 1
print(count)


# Optimized solution
# bitDPやりたくなるけどあきらかにオーバーキル
# ふつうにDFSする
n = int(eval(input()))


def dfs(cur):
    ret = 0
    for m in ["3", "5", "7"]:
        nex = cur
        nex += m
        if int(nex) <= n:
            if "7" in nex and "5" in nex and "3" in nex:
                ret += 1
            ret += dfs(nex)
    return ret


print((dfs("")))
# Original solution
import itertools
N = int(eval(input()))
ans = 0

for i in range(3, len(str(N)) + 1):
  for ptn in itertools.product((3, 5, 7), repeat=i):
    if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
        continue
    a = int("".join(list(map(str, ptn))))
    if a <= N:
      ans +=1

print(ans)

# Optimized solution
import itertools
N = int(eval(input()))
ans = 0
for i in range(1, 10):
  for x in itertools.product("753", repeat=i):
    s= ''.join(x)
    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
from itertools import product
N = int(eval(input()))
ans = 0
for k in range(3,11):
    for i in product([0,3,5,7],repeat=k):
        if set(i) != {3,5,7}:
            continue
        if sum([10**j*v for j,v  in enumerate(i)]) <= N:
            ans += 1
print(ans)


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


def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if len(set(s)) == 4 else 0
    for i in ('3', '5', '7'):
        ret += dfs(s+i)
    return ret


print((dfs('0')))
# Original solution
import itertools
N = int(eval(input()))
ans = 0
for i in range(3, 10):
    product = list(itertools.product(['3', '5', '7'], repeat=i))
    for li in product:
        if len(set(li)) == 3:
            if int(''.join(li)) <= N:
                ans += 1
print(ans)


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


def dfs(cur, use, cnt):
    if cur > N:
        return
    if use == 0b111:
        cnt.append(1)
    dfs(cur*10 + 7, use | 0b001, cnt)
    dfs(cur*10 + 5, use | 0b010, cnt)
    dfs(cur*10 + 3, use | 0b100, cnt)


res = []
dfs(0, 0, res)
print((sum(res)))
# Original solution
N = int(eval(input()))


def dfs(acc, sevens, fives, threes):
    if int(acc) > N:
        return 0
    is_hichigosan_num = False
    if sevens >= 1 and fives >= 1 and threes >= 1:
        is_hichigosan_num = True

    return sum([
        1 if is_hichigosan_num else 0,
        dfs(acc + '7', sevens+1, fives, threes),
        dfs(acc + '5', sevens, fives+1, threes),
        dfs(acc + '3', sevens, fives, threes+1)
    ])


print((dfs('0', 0, 0, 0)))


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


def dfs(acc):
    if int(acc) > N:
        return 0
    is_hichigosan_num = False
    if '7' in acc and '5' in acc and '3' in acc:
        is_hichigosan_num = True

    return sum([
        1 if is_hichigosan_num else 0,
        dfs(acc + '7'),
        dfs(acc + '5'),
        dfs(acc + '3')
    ])


print((dfs('0')))
# Original solution
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

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


# Optimized solution
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

N = int(input())

ans = 0
for n in range(3, 10):
    for l in it.product(["7", "5", "3"], repeat=n):
        if "7" not in l or "5" not in l or "3" not in l:
            continue
        M = int("".join(l))
        if M <= N:
            dump(M, ans)
            ans += 1
dump(N)
print(ans)
# Original solution
def nextn(n):
    if n == 0:
        return 3
    elif n % 10 == 3:
        return n+2
    elif n % 10== 5:
        return n+2
    elif n % 10 ==7:
        return nextn(n//10)*10 + 3

N = int(eval(input()))
n = 357
ans = 0
while n <= N:
    s = str(n)
    a = [False,False,False]
    for c in s:
        if c == '3':
            a[0] = True
        elif c == '5':
            a[1] = True
        elif c == '7':
            a[2] = True
        else:
            print(s)
    if all(a):
        ans += 1
    n = nextn(n) 
print(ans)


# Optimized solution
def nexti(i):
    if i == 0:
        return 3
    elif i % 10 == 3:
        return i + 2
    elif i % 10== 5:
        return i + 2
    elif i % 10 ==7:
        return nexti(i//10)*10 + 3

n = int(eval(input()))
nn = 0
i = 357

while i <= n:
  s = str(i)
  if '3' in s:
    if '5' in s:
      if '7' in s:
        #print(i)
        nn += 1
  if i % 10 == 7:
    i = nexti(i)
  else:
    i +=2
print(nn)
# Original solution
def nexti(i):
    if i == 0:
        return 3
    elif i % 10 == 3:
        return i + 2
    elif i % 10== 5:
        return i + 2
    elif i % 10 ==7:
        return nexti(i//10)*10 + 3

n = int(eval(input()))
nn = 0
i = 357

while i <= n:
  s = str(i)
  if '3' in s:
    if '5' in s:
      if '7' in s:
        #print(i)
        nn += 1
  if i % 10 == 7:
    i = nexti(i)
  else:
    i +=2
print(nn)

# Optimized solution
from itertools import product
N = int(eval(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)
# 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
N = int(eval(input()))
ans = 0

def dfs(x, a, b, c):
    global ans
    if x > N:
        return
    if (a & b & c):
        ans += 1
    dfs(10 * x + 3, 1, b, c)
    dfs(10 * x + 5, a, 1, c)
    dfs(10 * x + 7, a, b, 1)

dfs(0, 0, 0, 0)
print(ans)
# Original solution
def function(n):
    digit=len(str(n))
    N=str(n)
    if digit<3:
        return 0
    else:
        k=int(N[0])
        m=int(N[1])
        if k<3:
            return function(10**(digit-1)-1)
        elif k==3 and m>0:
            return function(10**(digit-1)-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(5,7,n%(10**(digit-1)))
        elif k==3 and m==0:
            return function(10**(digit-1)-1)
        elif k==4:
            return function(4*(10**(digit-1))-1)
        elif k==5 and m>0:
            return function(4*(10**(digit-1))-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(3,7,n%(10**(digit-1)))
        elif k==5 and m==0:
            return function(4*(10**(digit-1))-1)
        elif k==6:
            return function(6*(10**(digit-1))-1)
        elif k==7 and m>0:
            return function(6*(10**(digit-1))-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(3,5,n%(10**(digit-1)))
        elif k==7 and m==0:
            return function(6*(10**(digit-1))-1)
        else:
            return function(8*(10**(digit-1))-1)

def subfunction(a,b,n):
    digit=len(str(n))
    N=str(n)
    k=int(N[0])
    if digit<2:
        return 0
    else:
        if k<a:
            return 0
        elif k==a:
            if n%(10**(digit-1))<b*(10**(digit-1)-1)//9:
                s=0
            else:
                s=1
            return subfunction(a,b,n%(10**(digit-1)))+s
        elif a<k<b:
            return subfunction(a,b,(a+1)*(10**(digit-1))-1)
        elif k==b:
            if n%(10**(digit-1))<a*(10**(digit-1)-1)//9:
                s=0
            else:
                s=1
            return subfunction(a,b,(a+1)*(10**(digit-1))-1)+subfunction(a,b,n%(10**(digit-1)))+s
        else:
            return subfunction(a,b,(b+1)*(10**(digit-1))-1)

N=int(eval(input()))
print((function(N)))

# Optimized solution
import heapq

N=int(eval(input()))
count=0
que=[3,5,7]
heapq.heapify(que)
ans=[]
while True:
    x=heapq.heappop(que)
    if N>=x:
        count+=1
        ans.append(x)
    else:
        break
    heapq.heappush(que,10*x+3)
    heapq.heappush(que,10*x+5)
    heapq.heappush(que,10*x+7)

count=0
check=["3","5","7"]
for i in ans:
    for j in check:
        if str(i).count(j)==0:
            break
    else:
        count+=1

print(count)
# Original solution
from itertools import product

n = int(eval(input()))
res = 0
for pattern in product(["0", "3", "5", "7"], repeat=9):
    p = int("".join(pattern))
    if "0" not in str(p):
        for i in [3, 5, 7]:
            if str(i) not in str(p):
                break
        else:
            if p <= n:
                res += 1
            else:
                break
print(res)

# Optimized solution
from itertools import product

n = int(eval(input()))

res = 0
for pattern in product(["0", "3", "5", "7"], repeat=len(str(n))):
    p = int("".join(pattern))
    if "0" not in str(p):
        if p <= n:
            for i in ["3", "5", "7"]:
                if i not in str(p):
                    break
            else:
                res += 1
print(res)
# Original solution
from itertools import product

n = int(eval(input()))

res = 0
for pattern in product(["0", "3", "5", "7"], repeat=len(str(n))):
    p = int("".join(pattern))
    if "0" not in str(p):
        if p <= n:
            for i in ["3", "5", "7"]:
                if i not in str(p):
                    break
            else:
                res += 1
print(res)


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


def dfs(s):
    if int(s) > n:
        return 0
    for i in '753':
        if s.count(i) == 0:
            res = 0
            break
    else:
        res = 1
    for i in '753':
        res += dfs(s + i)

    return res


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


def dfs(s):
    if int(s) > n:
        return 0
    for i in '753':
        if s.count(i) == 0:
            res = 0
            break
    else:
        res = 1
    for i in '753':
        res += dfs(s + i)

    return res


print((dfs('0')))


# Optimized solution
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
res = 0


def resolve():
    n = int(eval(input()))

    def is_ok(L):
        l = "".join(L)
        if int(l) <= n:
            for i in ["7", "5", "3"]:
                if i not in l:
                    return False
            else:
                return True
        else:
            return False

    def dfs(L):
        global res
        if len(L) == len(str(n)):
            return

        for i in ["7", "5", "3"]:
            L.append(i)
            if is_ok(L):
                res += 1
            dfs(L)
            L.pop()

        return res

    print((dfs([])))


if __name__ == '__main__':
    resolve()
# Original solution
N = int(eval(input()))

l = len(str(10**9))
def dfs(A):#配列Aからできる753数
    global N
    if len(A)>0 and(int("".join(map(str, A)))>N):
        return 0
    
    ans = 0
    if(all(A.count(i)==0 for i in [0, 1, 2, 4, 6, 8, 9]) and (A.count(3) >0 and A.count(5) >0 and A.count(7) >0)):
        ans = ans + 1
    
    for i in [3, 5, 7]:
        A.append(i)
        ans = ans + dfs(A)
        A.pop()
    
    return ans
print((dfs([])))


# Optimized solution
N = int(eval(input()))
import sys
sys.setrecursionlimit(500000)
def dfs(l):
    global N

    if l!=[] and N<int("".join(l)):
        return 0
    ans = 0
    if all(l.count(i)>0 for i in ["3", "5", "7"]):
        ans = 1
    for i in ["3", "5", "7"]:
        l.append(i)
        #参照渡し
        ans += dfs(l)
        l.pop()

    return ans

print((dfs([])))
# Original solution
from itertools import product

n = int(eval(input()))
n_len = len(str(n))
ans = 0
for i in range(3,n_len):
    ite = product(list(range(3)),repeat=i)
    for it in ite:
        if 0 in it and 1 in it and 2 in it:
            ans += 1


num_d = {0:7,1:5,2:3}
ite = product(list(range(3)),repeat=n_len)
for it in ite:
    if 0 in it and 1 in it and 2 in it:
        curr_num = 0
        for i,j in enumerate(it):
            curr_num += num_d[j]*(10**(n_len-1-i))
        if curr_num <= n: 
            ans+=1

print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**6)


def dfs(curr_num, e753, list753, n):
    if curr_num > n: return
    if e753 == 7:
        list753.append(curr_num)
    dfs(curr_num*10+7, e753|4, list753, n)
    dfs(curr_num*10+5, e753|2, list753, n)
    dfs(curr_num*10+3, e753|1, list753, n)


def main():
    n = int(eval(input()))
    list753 = []
    dfs(0,0,list753,n)
    print((len(list753)))


if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))
q = [ 3, 5, 7 ]

ans = 0
while len(q) != 0:
    x = q.pop(0)
    for i in [ 3, 5 , 7]:
        y = 10 * x + i
        if ( y <= n):
            q.append(y)
            if '3' in str(y) and '5' in str(y) and '7' in str(y):
                ans += 1
print(ans)

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

def dfs(l):
    return sum([
        # next
        dfs(10 * l + i) if (10 * l + i) <= n else 0
        for i in [3, 5, 7]] +
        # current
        [1 if '3' in str(l) and '5' in str(l) and '7' in str(l) else 0]
        )

print((dfs(0)))
# Original solution
from collections import deque
n=int(eval(input()))
l=["3","5","7"]
q=deque(["3","5","7"])
l1=["3","5","7"]
count=0
while q:
  a=q.popleft()
  for i in l:
    if int(i+a)<=n:
      q.append(i+a)
      l1.append(i+a)
for i in l1:
  if ("3" in i) and ("5" in i) and ("7" in i):
    count+=1
print(count)

# Optimized solution
num=int(eval(input()))
def dfs(n):
  if n>num:
    return 0
  else:
    w=str(n)
    if w=="0":
      w=""
    if "3" in w and "7" in w and "5" in w:
      ret=1
    else:
      ret=0
    for i in "357":   
      ret+=dfs(int(i+w))
    return ret
print((dfs(0)))