CodeEff/ECCO huggingface dataset:
# Original solution
import heapq
def dijkstra(start,goal,graph):

    INF = 2 << 20
    node_num = len(graph) 
    visited = [False] * node_num
    costs = [INF] * node_num
    pq = []
    costs[start] = 0
    heapq.heappush(pq, [0,start])
    while not len(pq) == 0:

        cur_cost,cur_node = heapq.heappop(pq)
        if visited[cur_node]:
            continue
        if all(visited[1:]):
            break
        visited[cur_node] = True
        costs[cur_node] = cur_cost
        for i in range(node_num):
            if not visited[i]:
                heapq.heappush(pq,[graph[cur_node][i] + costs[cur_node],i])
    return costs[goal]

n = eval(input())
m = eval(input())
INF = 2 << 20
graph = [[INF] * (n+1) for _ in range(n+1)]
for _ in range(m):
    a,b,c,d = list(map(int,input().split(",")))
    graph[a][b] = c
    graph[b][a] = d
home,shop,reward,price = list(map(int,input().split(",")))
cost = dijkstra(home,shop,graph) + dijkstra(shop,home,graph)
print(reward - price - cost)

# Optimized solution
import heapq
def dijkstra(start,goal,graph):

    INF = 2 << 20
    node_num = len(graph) 
    visited = [False] * node_num
    costs = [INF] * node_num
    pq = []
    costs[start] = 0
    heapq.heappush(pq, [0,start])
    while not len(pq) == 0:

        cur_cost,cur_node = heapq.heappop(pq)
        if visited[cur_node]:
            continue
        visited[cur_node] = True
        costs[cur_node] = cur_cost
        for i in range(node_num):
            if not visited[i]:
                heapq.heappush(pq,[graph[cur_node][i] + costs[cur_node],i])
    return costs[goal]

n = eval(input())
m = eval(input())
INF = 2 << 20
graph = [[INF] * (n+1) for _ in range(n+1)]
for _ in range(m):
    a,b,c,d = list(map(int,input().split(",")))
    graph[a][b] = c
    graph[b][a] = d
home,shop,reward,price = list(map(int,input().split(",")))
cost = dijkstra(home,shop,graph) + dijkstra(shop,home,graph)
print(reward - price - cost)
# Original solution
INF = 1000000


def bellman_ford(graph, source):
    lg = len(graph)
    unused = list(range(lg))
    d = [INF] * (lg)
    d[source] = 0

    while unused:
        v = min(unused, key=lambda u: d[u])
        unused.remove(v)
        for u in range(n + 1):
            d[u] = min(d[u], d[v] + graph[v][u])

    return d

n = int(eval(input()))
m = int(eval(input()))

cost = [[INF] * (n + 1) for i in range(n + 1)]
for i in range(m):
    ai, bi, ci, di = list(map(int, input().split(',')))
    cost[ai][bi] = ci
    cost[bi][ai] = di

x1, x2, y1, y2 = list(map(int, input().split(',')))

d_go = bellman_ford(cost, x1)[x2]
d_back = bellman_ford(cost, x2)[x1]

print((y1 - y2 - d_go - d_back))

# Optimized solution
INF = 1e12


def dijkstra(graph, source):
    lg = len(graph)
    unused = list(range(lg))
    d = [INF] * (lg)
    d[source] = 0

    while unused:
        v = min(unused, key=lambda u: d[u])
        unused.remove(v)
        for u in range(n + 1):
            d[u] = min(d[u], d[v] + graph[v][u])

    return d

n = int(eval(input()))
m = int(eval(input()))

cost = [[INF] * (n + 1) for i in range(n + 1)]
for i in range(m):
    ai, bi, ci, di = list(map(int, input().split(',')))
    cost[ai][bi] = ci
    cost[bi][ai] = di

x1, x2, y1, y2 = list(map(int, input().split(',')))

d_go = dijkstra(cost, x1)[x2]
d_back = dijkstra(cost, x2)[x1]

print((y1 - y2 - d_go - d_back))
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

C = ord(read().decode('utf-8').rstrip())
C += 1

print((chr(96 + C % 96)))


# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

print((chr(ord(read().decode('utf-8').rstrip()) + 1)))
# Original solution
def search(s, n):
  if int(s) > n:
    return 0
  ans = 1 if (s.count('7') > 0 and s.count('5') > 0 and s.count('3') > 0) else 0
  for c in '753':
    ans += search(s+c,n)
  return ans

N = int(eval(input()))
print((search('0',N)))
    

# Optimized solution
def getSpecialNum(x, n):	
	if int(x) > n:
		return 0
	ans = 0
	if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
		ans = 1
	ans += getSpecialNum(x+'3',n)
	ans += getSpecialNum(x+'5',n)
	ans += getSpecialNum(x+'7',n)
	return ans
N = int(eval(input()))
print((getSpecialNum('0',N)))
# Original solution
from math import ceil, log10
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(2, ceil(log10(n))):
        tmp = [
            int("".join(x))
            for x in product("753", repeat=i + 1)
            if "7" in x and "5" in x and "3" in x
        ]
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print((solve(eval(input()))))


# Optimized solution
from math import ceil, log10
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(2, ceil(log10(n))):
        tmp = (int("".join(x))
               for x in product("753", repeat=i + 1)
               if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print((solve(eval(input()))))
# Original solution
from math import ceil, log10
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(2, ceil(log10(n))):
        tmp = (int("".join(x))
               for x in product("753", repeat=i + 1)
               if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print((solve(eval(input()))))


# Optimized solution
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(3, len(str(n)) + 1):
        tmp = (int("".join(x))
               for x in product("753", repeat=i)
               if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print((solve(eval(input()))))
# Original solution
N = int(eval(input()))
ans = 0

def dfs(n):
  global ans
  if n > N:
    return
  else:
    if all(str(n).count(c) > 0 for c in "357"):
      ans += 1
    dfs(10*n + 3)
    dfs(10*n + 5)
    dfs(10*n + 7)

dfs(0)
print(ans)

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

def dfs(n):
  ans = 0
  if n > N:
    return 0
  else:
    if all(str(n).count(c) > 0 for c in "357"):
      ans = 1
    ans += dfs(10*n + 3)
    ans += dfs(10*n + 5)
    ans += dfs(10*n + 7)
  return ans

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

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

print((solve('0')))

# Optimized solution
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(eval(input()))
print((dfs('0')))
# Original solution
import bisect
n = int(eval(input()))
l = len(str(n))

ary = []

siti = ["3","5","7"]
def dfs (s,t):
	if len(s) == t:
		if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
			ary.append(int(s))
		return
	for j in siti:
		dfs(s+j,t)

for i in range(3,l+1):
	dfs("",i)

ary.sort()
print((bisect.bisect_right(ary,n)))

# Optimized solution
import bisect
n = int(eval(input()))
l = len(str(n))
ary = []
siti = ["3","5","7"]
def dfs (s,t):
	if len(s) == t:
		if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
			ary.append(int(s))
		return
	for j in siti:
		dfs(s+j,t)
for i in range(3,l+1):
	dfs("",i)
# ary.sort()
print((bisect.bisect_right(ary,n)))
# Original solution
import sys
sys.setrecursionlimit(10**7)

n = int(eval(input()))

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

res = []
search(0, 0, res)
print((sum(res)))

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

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

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

search(0, 0)
print((sum(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
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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


if __name__ == '__main__':
    main()
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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


if __name__ == '__main__':
    main()


# Optimized solution
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()

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')))
# Original solution
# https://atcoder.jp/contests/abc114/submissions/6262572

from itertools import product
N = eval(input())
n = int(N)
ans = 0
for i in range(3,10):
    for s in product(["3","5","7"],repeat=i):
        if int("".join(s)) <= n and "3" in s and "5" in s and "7" in s:
            ans += 1
print(ans)


# Optimized solution
# https://atcoder.jp/contests/abc114/submissions/6262572

from itertools import product
N = int(eval(input()))
ans = 0
for i in range(3,10):
    for s in product(["3","5","7"],repeat=i):
        if int("".join(s)) <= N and "3" in s and "5" in s and "7" in s:
            ans += 1
print(ans)
# Original solution
N = int(eval(input()))

# 再帰で全探索, sは文字列とすると便利
def dfs( s ):
    # 現在の数字が N を越えたら終わり
    if int( s ) > N: return 0
    # s 自体が七五三数なら +1, 他なら 0
    ret = 1 if all( s.count(c) > 0 for c in '753' ) else 0 
    # 最後尾に3,5,7を加えて新たな七五三数を作る
    for c in '753':
         ret += dfs(s + c)
    return ret

print(( dfs('0') )) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため

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

# 再帰で全探索, sは文字列とすると便利
def dfs( s ):
    # 現在の数字が N を越えたら終わり
    if int( s ) > N: return 0
    # s が七五三数なら +1, 他なら 0
    ans = 1 if all( s.count(c) > 0 for c in '753' ) else 0 
    # 最後尾に3,5,7を加えて新たな七五三数を作る
    for c in '753':
         ans += dfs(s + c)
    return ans

print(( dfs('0') ))
# Original solution
def dfs(s,flag):
    if s>N:
        return 0
    ret =1 if flag==7 else 0
    ret+=dfs(s*10+3,flag|1)    
    ret+=dfs(s*10+5,flag|2)
    ret+=dfs(s*10+7,flag|4)
    return ret

N=int(eval(input()))
print((dfs(0,0)))


# Optimized solution
def dfs(s,flag):
    if s>upbd:
        return 0
    ret =1 if flag==7 else 0
    ret+=dfs(s*10+3,flag|1)    
    ret+=dfs(s*10+5,flag|2)
    ret+=dfs(s*10+7,flag|4)
    return ret

upbd=int(eval(input()))
print((dfs(0,0)))
# Original 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)) == 4

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 rec(x):
    # print(x)
    ans = 0
    c = int(x)
    if c > N:
        return 0
    if check(x):
        ans += 1
    # if ans == 1:
    #     print(x)
    for s in '357':
        ans += rec(x + s)
    return ans

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

if __name__ == '__main__':
    main()


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

def rec(s, n):
    c = 0
    if s == '':
        s = '0'
    if int(s) > n:
        return 0
    if len(set(s)) == 4:
        # print(s)
        c += 1
    for i in '357':
        w = s + i
        c += rec(w, n)
    return c

def main():
    n = int(input().strip())
    print((rec('', n)))

if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))

def dfs(s):
	if int(s) > n:#nより大きいならカウントしない
		#print(int(s))
		return 0

	ret = 1 if all(s.count(c) > 0 for c in '753') else 0
	#753,全てが含まれているなら1
	
	for c in '753':
		ret += dfs(s+c)
		#print(s+c)
	return ret

print((dfs('0')))




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



def dfs(s):
	if int(s)>limit:
		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 check_753(s):
  s = str(int(s))
  a = ''.join(sorted(list(set(s))))
  if a == '357':
    return True
  else:
    return False

def shi(s):
  if int(s) > N:
    return 0
  if check_753(s):
    ret = 1
  else:
    ret = 0
  for i in '753':
    ret += shi(s+i)
  return ret

print((shi('0')))


# Optimized solution
import itertools as t

N = int(eval(input()))

L = [ int(''.join(j)) for i in range(10) for j in t.product(['3','5','7'], repeat=i) if '3' in j and '5' in j and '7' in j]
L = [i for i in L if i <= N]
print((len(L)))
# Original solution
n = int(eval(input()))
 
def dfs(s):

    if int(s) > n:
        return 0
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1
    else:
        cnt = 0
    cnt += dfs(s + '3')
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt
  
print((dfs('0')))

# Optimized solution
n = int(eval(input())) 
def dfs(s):
    if int(s) > n:
        return 0 #再帰の終了条件
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1 #３か、５か、７が、１回は出てくる⇒カウントアップ
    else:
        cnt = 0
    cnt += dfs(s + '3') #再帰、３か、５か、７か、を繰り返す
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt #求めたいのは、出現回数
  
print((dfs('0'))) #スタートはゼロ
# Original solution
N = int(eval(input()))
def dfs(s): # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        # print("invalid  ",s)
        return 0
    # print("valid    ",s)
    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'))) 

# Optimized solution
from collections import deque
N = int(eval(input()))
stack = deque(["0"])
cnt = 0
while len(stack)>0:
    c = stack.pop()
    for s in "753":
        cs = c + s
        # print(cs)
        if int(cs)<=N:
            stack.append(cs)
            if cs.count("3")*cs.count("5")*cs.count("7")>0:
                cnt += 1
print(cnt)
# Original solution
def main():
    from collections import deque

    N = int(eval(input()))

    dq = deque()
    dq.append(0)

    ans = 0
    while dq:
        x = dq.popleft()
        for a in (7, 5, 3):
            t = x * 10 + a
            if t > N: continue
            if all(c in str(t) for c in '753'):
                ans += 1
            dq.append(t)
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


# Optimized solution
def main():
    from collections import deque

    N = int(eval(input()))

    dq = deque([0])
    cnt = 0
    while dq:
        x = dq.popleft()
        if all(c in str(x) for c in '357'):
            cnt += 1
        for k in (3, 5, 7):
            nx = x * 10 + k
            if nx <= N:
                dq.append(nx)
    print(cnt)


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

# Optimized solution
#coding: utf-8
from collections import Counter
N = int(eval(input()))
l = ["0", "3", "5", "7"]
ans = ["0"] * 9
cnt = 0
for a in l:
    ans[0] = a
    for b in l:
        ans[1] = b
        for c in l:
            ans[2] = c
            for d in l:
                ans[3] = d
                for e in l:
                    ans[4] = e
                    for f in l:
                        ans[5] = f
                        for g in l:
                            ans[6] = g
                            for h in l:
                                ans[7] = h
                                for i in l:
                                    ans[8] = i
                                    ans_i = int("".join(ans))
                                    ans_c = Counter(str(ans_i))
                                    if ans_i <= N and "0" not in str(ans_i) and len(list(ans_c.keys())) == 3 and len(str(ans_i)) >= 3:
                                        cnt += 1
print(cnt)
# Original solution
n = int(eval(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)

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

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

print(ans)
# Original solution
N = int(eval(input()))
def dfs(s):
    if int(s) > N:
        return 0
    else:
        if '7' in s and '5' in s and '3' in s:
            ret = 1
        else:
            ret = 0
        for i in '357':
            ret += dfs(s + i)
        return ret
print((dfs("0")))

# Optimized solution
from itertools import product

N = int(eval(input()))
ans = 0
for j in range(3, len(str(N))+1):
    for i in product("357", repeat=j):
        x = "".join(i)
        if 357 <= int(x) <= N and len(set(x)) == 3:
            ans += 1
print(ans)
# Original solution

n = int(eval(input()))
l = len(str(n))

from itertools import product

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

count = 0
for i in range(3, l+1):
  for j in list(product(*[a for _ in range(i)])):
    if "3" in j and "5" in j and "7" in j:
      num = int("".join(j))
      if num <= n:
        count += 1

print(count)

# Optimized solution


N = int(eval(input()))
from itertools import product
S = ["3", "5", "7"]

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

print(ans)
# Original solution
N=int(eval(input()))
res = 0

def trans753(i):
    dict753=['0','3','5','7']
    num753=""
    while i>0:
        num753+=dict753[i%4]
        i//=4
    return int(num753[::-1])

def verify753(i):
    if '0' in str(i):
        return False
    flag = [False for i in range(10)]
    while i>0:
        flag[i%10]=True
        i//=10
    return flag[7] and flag[5] and flag[3]

for i in range(1,4**10):
    num753 = trans753(i)
    if num753>N:
        break
    if verify753(num753):
        res+=1

print(res)


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

def trans753(i):
    dict753=['0','3','5','7']
    num753=""
    while i>0:
        num753 = dict753[i%4] + num753
        i//=4
    return int(num753)

def verify753(i):
    if '0' in str(i):
        return False
    flag = [False for i in range(10)]
    while i>0:
        flag[i%10]=True
        i//=10
    return flag[7] and flag[5] and flag[3]

for i in range(1,4**10):
    num753 = trans753(i)
    if num753>N:
        break
    if verify753(num753):
        res+=1

print(res)
# Original solution
from itertools import product
n = int(eval(input()))
i = len(str(n))

cnt = 0
for j in range(3, i+1):
    for k in product(["3", "5", "7"], repeat=j):
        if len(set(k)) != 3:
            continue
        if int("".join(k)) <= n:
            cnt += 1

print(cnt)

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


def dfs(current, judge, count):
    if current > N:
        return
    if judge == 0b111:
        count.append(1)

    dfs(current * 10 + 7, judge | 0b100, count)
    dfs(current * 10 + 5, judge | 0b010, count)
    dfs(current * 10 + 3, judge | 0b001, count)


cnt = []
dfs(0, 0, cnt)
print((sum(cnt)))
# Original 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())))))


# Optimized solution
import itertools,bisect

num_list = []#753数となりえる数の生成
for i in range(3,10):
    num_list += list(itertools.product('753',repeat=i) )
    
num = []#753数の絞り込み
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
import bisect
N = int(eval(input()))
seven53 = []
def dfs(cur, s):
    if all(s.count(c) > 0 for c in "753"):
        seven53.append(s)
    if cur > 8:
        return
    else:
        for i in "753":
            dfs(cur + 1, s+i)
dfs(0, "")
seven53 = list(map(int, seven53))
seven53.sort()
print((bisect.bisect_right(seven53, N)))

# Optimized solution
import bisect
N = int(eval(input()))
seven53 = []
def dfs(s):
    if all(s.count(c) > 0 for c in "753"):
        seven53.append(s)
    if len(s) > 8:
        return
    else:
        for i in "753":
            dfs(s+i)
dfs("")
seven53 = list(map(int, seven53))
seven53.sort()
print((bisect.bisect_right(seven53, N)))