CodeEff/ECCO huggingface dataset:
# Original solution
# -*- coding: utf-8 -*-
from collections import deque


class LinkedList:
    def __init__(self, n):
        self.n = n
        self.ll = [[] for _ in range(self.n)]

    def link(self, u, v, direction=False):
        self.ll[u].append(v)
        if not direction:
            self.ll[v].append(u)

    def check(self, start, goal):
        states = [0] * self.n
        queue = deque([start])

        while queue:
            u = queue.popleft()
            # if states[u]:
            #     continue
            # else:
            states[u] = 1

            for v in self.ll[u]:
                if v == goal:
                    print('yes')
                    return

                if states[v]:
                    continue
                else:
                    queue.append(v)

        else:
            print('no')
            return


if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    ll = LinkedList(n)

    for _ in range(m):
        u, v = list(map(int, input().split()))
        ll.link(u, v)

    q = int(eval(input()))
    for _ in range(q):
        u, v = list(map(int, input().split()))
        ll.check(u, v)



# Optimized solution
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)


class LinkedList:
    def __init__(self, n):
        self.n = n
        self.ll = [[] for _ in range(self.n)]

    def link(self, u, v, direction=False):
        self.ll[u].append(v)
        if not direction:
            self.ll[v].append(u)

    def dfs(self):
        self.cc = [None] * self.n

        color = 1
        for u in range(self.n):
            if not self.cc[u]:
                self.dfs_visit(u, color)
                color += 1

    def dfs_visit(self, u, color):
        self.cc[u] = color
        for v in self.ll[u]:
            if not self.cc[v]:
                self.dfs_visit(v, color)

    def check(self, u, v):
        if self.cc[u] == self.cc[v]:
            print('yes')
        else:
            print('no')


if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    ll = LinkedList(n)

    for _ in range(m):
        u, v = list(map(int, input().split()))
        ll.link(u, v)
    ll.dfs()

    q = int(eval(input()))
    for _ in range(q):
        u, v = list(map(int, input().split()))
        ll.check(u, v)
# Original solution
from collections import deque

def main():
    n, m = list(map(int,input().split()))
    A = [[] for i in range(n)]
    for i in range(m):
        s, t = list(map(int,input().split()))
        A[s].append(t)
        A[t].append(s)

    g = [-1]*n
    p = 1
    res = set(range(n))
    for i in range(n):
        if i in res:
            color = bfs(n,A,i,-1)
            c = []
            for j in range(n):
                if color[j] == 1:
                    c.append(i)
                    g[j] = p
            res = res - set(c)
            p += 1
            
    q = eval(input())
    a =[0]*q
    for i in range(q):
        s, t = list(map(int,input().split()))
        if g[s] == g[t]:
            a[i] = 'yes'
        else:
            a[i] = 'no'
    for i in a:
        print(i)
        
def bfs(n,A,s,t):
    color = [-1]*n
    Q = deque([s])
    while(True):
        if len(Q)==0:
            break
        u = Q.popleft()
        for i in A[u]:
            if i == t:
                color[t] = 1
                break
            elif color[i] == -1:
                color[i] = 0
                Q.append(i)
        color[u] = 1
    return color

if __name__ == '__main__':
    main()

# Optimized solution
from collections import deque

def main():
    n, m = list(map(int,input().split()))
    A = [[] for i in range(n)]
    for i in range(m):
        s, t = list(map(int,input().split()))
        A[s].append(t)
        A[t].append(s)

    g = [-1]*n
    x = 0
    for i in range(n):
        if g[i] == -1:
            g = bfs(n,A,i,g,x)
            x += 1
            
    q = eval(input())
    a =[0]*q
    for i in range(q):
        s, t = list(map(int,input().split()))
        if g[s] == g[t]:
            a[i] = 'yes'
        else:
            a[i] = 'no'
    for i in a:
        print(i)
        
def bfs(n,A,s,color,x):
    Q = deque([s])
    while(len(Q)!=0):
        u = Q.popleft()
        for i in A[u]:
            if color[i] == -1:
                Q.append(i)
        color[u] = x
    return color

if __name__ == '__main__':
    main()
# Original solution
from collections import deque

n, m = list(map(int, input().split()))
g = [set() for _ in range(n)]
group_ids = [0] * n

while m:
    s, t = list(map(int, input().split()))
    g[s].add(t)
    g[t].add(s)
    m -= 1


def search(s, gid):
    global g, group_ids
    queue = set()
    queue.add(s)
    visited = [0] * n
    visited[s] = 1
    group_ids[s] = gid

    while queue:
        i = queue.pop()
        for f in g[i]:
            if not visited[f]:
                visited[f] = 1
                group_ids[f] = gid
                queue.add(f)


gid = 1
for i in range(n):
    if group_ids[i]:
        continue
    search(i, gid)
    gid += 1

q = int(eval(input()))
while q:
    s, t = list(map(int, input().split()))
    gs, gt = group_ids[s], group_ids[t]
    print(('yes' if gs and gt and gs == gt else 'no'))
    q -= 1

# Optimized solution
n, m = list(map(int, input().split()))
g = [set() for _ in range(n)]
group_ids = [0] * n

while m:
    s, t = list(map(int, input().split()))
    g[s].add(t)
    g[t].add(s)
    m -= 1


def search(s, gid):
    global g, group_ids
    queue = set(g[s])
    group_ids[s] = gid

    while queue:
        i = queue.pop()
        if not group_ids[i]:
            group_ids[i] = gid
            queue.update(g[i])


gid = 1
for i in range(n):
    if group_ids[i]:
        continue
    search(i, gid)
    gid += 1

q = int(eval(input()))
while q:
    s, t = list(map(int, input().split()))
    gs, gt = group_ids[s], group_ids[t]
    print(('yes' if gs and gt and gs == gt else 'no'))
    q -= 1
# Original solution
from collections import deque


def dfs(G, C, id, color):
    S = deque()
    S.append(id)
    C[id] = color

    while S:
        u = S.pop()
        #S = S[:-1]  # pop
        for i in range(len(G[u])):
            v = G[u][i]
            if C[v] == -1:
                C[v] = color
                S.append(v)


if __name__ == '__main__':
    # ??????????????\???
    num_of_users, num_of_links = [int(x) for x in input().split(' ')]
    links = []
    for _ in range(num_of_links):
        links.append(list(map(int, input().split(' '))))
    num_of_queries = int(eval(input()))
    queries = []
    for _ in range(num_of_queries):
        queries.append(list(map(int, input().split(' '))))

    # ???????????????
    G = [[] for _ in range(100000)]
    C = [-1] * 100000
    for f, t in links:
        G[f].append(t)
        G[t].append(f)

    color = 1
    for id in range(num_of_users):
        if C[id] == -1:
            dfs(G, C, id, color)
        color += 1

    # ???????????????
    for x, y in queries:
        if C[x] == C[y]:
            print('yes')
        else:
            print('no')

# Optimized solution
# -*- coding: utf-8 -*-
"""

"""

import sys
sys.setrecursionlimit(1000000)


n,m=[int(i) for i in input().split()]
graph=[[] for i in range(n)]

for i in range(m):
    relation=[int(j) for j in input().split()]
    graph[relation[0]].append(relation[1])
    graph[relation[1]].append(relation[0])


check=[0 for i in range(n)]
rabel=0
stack=[]

#深さ優先探索
def dfs(graph,i):
    global stack
    global n
    global rabel

    if check[i]==0:

        #行った足跡をつける
        check[i]=rabel

        #今いる場所の情報
        now=graph[i]

        #スタックに入れる
        stack.append(now)

        #今いる場所から到達できる地点のうち、まだ行っていないとこ全部でdfs
        for j in now:
            if check[j]==0:
                dfs(graph,j)

        stack.pop()

for i in range(n):
    if check[i]==0:
        rabel+=1
        dfs(graph,i)
# print(check)



num=int(eval(input()))
for i in range(num):
    a,b=[int(j) for j in input().split()]
    if check[a]==check[b]:
        print("yes")
    else:
        print("no")
# Original solution
n, m = list(map(int, input().split()))
G = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    s, t = list(map(int, input().split()))
    G[s][t] = 1
    G[t][s] = 1

for i in range(n):
    for j in range(n):
        for k in range(n):
            if G[j][k] == 1:
                for l in range( n):
                    if G[k][l] == 1:
                        G[j][l] = 1
                        G[l][j] = 1

q = int(input())
ans = ["no" for i in range(q)]
for i in range(q):
    s, t = list(map(int, input().split()))
    if G[s][t] == 1:
        ans[i] = "yes"
for i in range(q):
    print((ans[i]))

# Optimized solution
def DFS(s):
    flag[s] = 1
    group[s] = j
    for i in range(n):
        if i in G[s] and flag[i] == 0:
            DFS(i)

n, m = list(map(int, input().split()))
G = [[] for j in range(n)]

for i in range(m):
    s, t = list(map(int, input().split()))
    G[s].append(t)
    G[t].append(s)

group = [[] for i in range(n)]
flag = [0 for i in range(n)]
j = 0
for i in range(n):
    if flag[i] == 0:
        DFS(i)
        j += 1

q = int(eval(input()))
for i in range(q):
    s, t = input().split()
    if group[int(s)] == group[int(t)]:
        print("yes")
    else:
        print("no")
# Original solution
import sys
from collections import deque

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def paint_col(adj, cols, i, col):
    nxt = deque([i])

    while nxt:
        u = nxt.popleft()
        cols[u] = col
        for child in adj[u]:
            if cols[child] == 0:
                nxt.append(child)

def solve():
    n, m = map(int, input().split())
    adj = [[] for i in range(n)]

    for i in range(m):
        s, t = map(int, input().split())
        adj[s].append(t)
        adj[t].append(s)

    cols = [0] * n
    col = 1

    for i in range(n):
        if cols[i] == 0:
            paint_col(adj, cols, i, col)
            col += 1

    q = int(input())

    for i in range(q):
        s, t = map(int, input().split())

        if cols[s] == cols[t]:
            ans = 'yes'
        else:
            ans = 'no'

        print(ans)

if __name__ == '__main__':
    solve()


# Optimized solution
import sys
from collections import deque

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def paint_col(adj, cols, i, col):
    nxt = deque([i])

    while nxt:
        u = nxt.popleft()
        cols[u] = col
        for child in adj[u]:
            if cols[child] == 0:
                nxt.append(child)

def solve():
    n, m = map(int, sys.stdin.readline().split())
    adj = [[] for i in range(n)]

    for i in range(m):
        s, t = map(int, sys.stdin.readline().split())
        adj[s].append(t)
        adj[t].append(s)

    cols = [0] * n
    col = 1

    for i in range(n):
        if cols[i] == 0:
            paint_col(adj, cols, i, col)
            col += 1

    q = int(sys.stdin.readline())

    for i in range(q):
        s, t = map(int, sys.stdin.readline().split())

        if cols[s] == cols[t]:
            ans = 'yes'
        else:
            ans = 'no'

        print(ans)

if __name__ == '__main__':
    solve()
# Original solution
#template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(eval(input()))
L = inputlist()
L.sort()
s = 0
for i in range(N-1):
    s += L[i]
if s > L[-1]:
    print("Yes")
else:
    print("No")

# Optimized solution
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N = int(eval(input()))
L = inputlist()
L.sort()
s=sum(L)
s -=L[-1]
if L[-1] < s:
    print("Yes")
else:
    print("No")
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))

s=sum(l)
m=max(l)
ans='Yes' if s>m*2 else 'No'
print(ans)

# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))
print(('YNeos'[max(l)*2>=sum(l)::2]))
# Original solution
N = int(eval(input()))
Length = list(map(int, input().split()))
if sum(Length) > 2*max(Length):
  print("Yes")
else:
  print("No")


# Optimized solution
N = int(eval(input()))
L = list(map(int, input().split()))
if 2*max(L)<sum(L):
  print("Yes")
else:
  print("No")
# Original solution
n = int(eval(input()))
ans, q = 0, ["3", "5", "7"]

while q:
    p = q.pop()
    for s in ["3", "5", "7"]:
        t = p + s
        if int(t) <= n:
            q.append(str(t))
            if len(list(set(list(str(t))))) == 3:
                ans += 1

print(ans)

# Optimized solution
n = int(eval(input()))
ans = 0
list_N = [["3", "5", "7"]]

for i in range(2, 10):
    d = []
    for a in list_N[-1]:
        for b in ["3", "5", "7"]:
            k = b + a
            if n >= int(k) and "3" in k and "5" in k and "7" in k:
                ans += 1
            d.append(k)
    list_N.append(d)

print(ans)
# Original solution
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(eval(input()))

def F(list_):
    if list_ and int("".join(map(str, list_))) > N:
        return
    
    if 3 in list_ and 5 in list_ and 7 in list_:
        yield 1
    
    for v in [3, 5, 7]:
        list_.append(v)
        yield from F(list_)
        list_.pop()
    return

ans = sum(F([]))
print(ans)

# Optimized solution
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

ans = dfs("0")
print(ans)
# Original solution
n=int(eval(input()))
num=[3,5,7]
#a[0]=3,a[1]=5,a[7]=5
ans=[3,5,7]
answ=[]
for i1 in range(3):
  for i2 in range(3):
    for i3 in range(3):
      a=set([i1,i2,i3])
      if len(a)>2:
        answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])))
      for i4 in range(3):
        a=set([i1,i2,i3,i4])
        if len(a)>2:
          answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i4])))
        for i5 in range(3):
          a=set([i1,i2,i3,i4,i5])
          if len(a)>2:
            answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i5])+str(num[i4])))
          for i6 in range(3):
            a=set([i1,i2,i3,i4,i5,i6])
            if len(a)>2:
              answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i6])+str(num[i5])+str(num[i4])))
            for i7 in range(3):
              a=set([i1,i2,i3,i4,i5,i6,i7])
              if len(a)>2:
                answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
              for i8 in range(3):
                a=set([i1,i2,i3,i4,i5,i6,i7,i8])
                if len(a)>2:
                  answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
                for i9 in range(3):
                  a=set([i1,i2,i3,i4,i5,i6,i7,i8,i9])
                  if len(a)>2:
                    answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i9])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
answ.sort()
left=0
right=len(answ)
while right-left>1:
  mid=(left+right)//2
  
  if n<answ[mid]:
    right=mid
  else:
    left=mid
if 357>n:
  print((0))
else:
  print((left+1))
                    
                

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

def dfs(s):
  if s!="" and int(s)>n:
    return 0
  
  if len(set(list(s)))<3:
    ret=0
  else:
    ret=1
  
  for i in "753":
    ret+=dfs(s+i)
  
  return ret

print((dfs("")))
# Original solution
n=int(eval(input()))
c=0
l=[3,5,7]
L=[]
for i1 in l:
  for i2 in l:
    for i3 in l:
      for i4 in l:
        for i5 in l:
          L.append(10000*i1+1000*i2+100*i3+10*i4+i5)
for i in range(min(n+1,10000)):
  l=str(i)
  if '3' in l and '5' in l and '7' in l and '0' not in l and '1' not in l and '2' not in l and '4' not in l and '6' not in l and '8' not in l and '9' not in l:c+=1
for j in L:
  for i in range(j,n+1,100000):
    l=str(i)
    if '3' in l and '5' in l and '7' in l and '0' not in l and '1' not in l and '2' not in l and '4' not in l and '6' not in l and '8' not in l and '9' not in l:c+=1
print(c)

# Optimized solution
n=int(eval(input()))
c=0
l=[0,3,5,7]
for i1 in l:
 for i2 in l:
  for i3 in l:
   for i4 in l:
    for i5 in l:
     for i6 in l:
      for i7 in l:
       for i8 in l:
        for i9 in l:
         x=str(i1+10*i2+100*i3+1000*i4+10000*i5+100000*i6+1000000*i7+10000000*i8+100000000*i9)
         if '3' in x and '5' in x and '7' in x and '0' not in x and int(x)<=n:c+=1
print(c)
# Original solution
import sys
n = int(eval(input()))
if n < 357:
  print((0))
  sys.exit()

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
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int):
    LEN = len(str(N))
    if LEN <= 2:
        print((0))
        return

    answer = 0
    for i in range(3,LEN+1):
        for num in list(itertools.product(['3','5','7'], repeat=i)):

            if num.count('3') >= 1 and num.count('5')>=1 and num.count('7') >=1 and int(''.join(num))<=N:
                answer +=1

    print(answer)
    return


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

if __name__ == '__main__':
    main()
# Original solution
def Base_10_to_n(x,n):
	if (int(x/n)):
		return Base_10_to_n(int(x/n),n)+str(x%n)
	return str(x%n)
	
n=int(eval(input()))
l=len(str(n))

res=0

for i in range(4**l):
	x=Base_10_to_n(i,4)
	cnt=0
	if not "0" in x: 
		if ("3" in x) and ("2" in x) and ("1" in x):
			for j in range(len(x)):
				if x[j]=="1":
					cnt+=3*(10**j)
				elif x[j]=="2":
					cnt+=5*(10**j)
				elif x[j]=="3":
					cnt+=7*(10**j)
			if cnt<=n:
				res+=1
			
print(res)
		

# Optimized solution
n=int(eval(input()))
A=["3","5","7"]
A=set(A)
cnt=0

for _ in range(len(str(n))-1):
	for a in list(A):
		x=a+"3"
		y=a+"5"
		z=a+"7"
		if int(x)<=n:
			A.add(x)
		if int(y)<=n:
			A.add(y)
		if int(z)<=n:
			A.add(z)

res=0

for a in list(A):
	if "3" in a and "5" in a and "7" in a:
		res+=1		

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

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

print((dfs("0")))

# Optimized solution
from sys import stdin
from collections import deque
def main():
    #入力
    readline=stdin.readline
    N=int(readline())

    #dfs
    count=0
    stack=deque(["0"])
    while len(stack)>=1:
        t=stack.pop()
        for s in "357":
            now=t+s
            if int(now)>N:
                break
            if ("7" in now) and ("5" in now) and ("3" in now):
                count+=1
            stack.append(now)
    
    print(count)

if __name__=="__main__":
    main()
# Original solution
import sys
sys.setrecursionlimit(1000000000)
LET=('3','5','7')
n=int(eval(input()))

def dfs(s):
  cnt = 0
  if len(s) >0 and int(s) > n:
    return cnt
  if s.count('3') > 0 and s.count('5')>0 and s.count('7')>0:
    cnt += 1
  for l in LET:
    cnt += dfs(s+l)
  return cnt

print((dfs('')))

# Optimized solution
import sys
sys.setrecursionlimit(10000000)
n=int(eval(input()))
tex=['3','5','7']

def dfs(value):
  ans=0
  if value != '' and int(value) > n:
    return 0
  for x in tex:
    if not x in value:
      break
  else:
    ans += 1 
  for x in tex:
    ans += dfs(value+x)
  #print(value,ans)
  return ans

print((dfs('')))
# Original solution
N = int(eval(input()))
ans = 0
for i in range(1, (4 ** 9)+1):
    tmp = ""
    now = i
        
    while now != 0:
        if now % 4 == 0:
            tmp += "0"
        elif now % 4 == 1:
            tmp += "3"
        elif now % 4 == 2:
            tmp += "5"
        else:
            tmp += "7"

        now //= 4

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


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

ans = [0]

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

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

print((ans[0]))
# Original solution
from collections import Counter
ls=[]
def rec(n):
    if len(str(n))>9: return
    ls.append(n)
    rec(n*10+3)
    rec(n*10+5)
    rec(n*10+7)
n=int(eval(input()))
rec(3)
rec(5)
rec(7)
cnt=0
for l in ls:
    temp=Counter(str(l))
    if l<=n and len(list(temp.keys()))==3:
        cnt+=1
print(cnt)

# Optimized solution
ls=[]
def rec(n):
    if len(str(n))>9: return
    ls.append(n)
    for i in [3,5,7]: rec(10*n+i)
n=int(eval(input()))
rec(0)
cnt=0
for l in ls:
    if l<=n and all(str(l).count(i)>0 for i in "357"): cnt+=1
print(cnt)
# Original solution
import math
n_in = int(eval(input()))


def sgs(n, a, s, s_temp):
    if a == math.ceil(math.log(n, 10)):
        c = 0
        for i in s:
            i_listed = list(map(int, list(str(i))))
            if 3 in i_listed and 5 in i_listed and 7 in i_listed:
                if i <= n:
                    c += 1
    else:
        a += 1
        temp = []
        for i in s_temp:
            s.append(10 * i + 3)
            s.append(10 * i + 5)
            s.append(10 * i + 7)
            temp.append(10 * i + 3)
            temp.append(10 * i + 5)
            temp.append(10 * i + 7)
        s_temp = temp
        c = sgs(n, a, s, s_temp)
    return c


ans = sgs(n_in, -1, [3, 5, 7], [3, 5, 7])
print(ans)


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


def generate(n):
    _list = []
    queue = collections.deque([0])
    while queue:
        _temp = queue.popleft()
        if _temp <= n and '3' in str(_temp) and '7' in str(_temp) and '5' in str(_temp):
            _list.append(_temp)
        if len(str(_temp)) > 9:
            break
        queue.append(_temp * 10 + 7)
        queue.append(_temp * 10 + 5)
        queue.append(_temp * 10 + 3)
    return _list


_list = generate(N)
print((len(_list)))
# Original solution
N = int(eval(input()))
def n_ary(l,d): # リストl中の文字でd桁までを全列挙(sorted)
    if d == 1:
        return(l)
    n = len(l)
    ll = n_ary(l,d-1)
    lll = []
    for i in l:
        for j in ll[n*(n**(d-2)-1)//(n-1):]:
            lll.append(i+j)
    return(ll+lll)
possible = [i.replace('0','3').replace('1', '5').replace('2','7') for i in n_ary(['0','1','2'],9)] # 制約が10^9なので9
print((len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= N)])))


# Optimized solution
N = int(eval(input()))
def n_ary(l,d): # リストl中の文字でd桁までを全列挙(sorted)
    if d == 1:
        return(l)
    n = len(l)
    ll = n_ary(l,d-1)
    lll = []
    for i in l:
        for j in ll[n*(n**(d-2)-1)//(n-1):]:
            lll.append(i+j)
    return(ll+lll)
possible = [i for i in n_ary(['3','5','7'],9)] # 制約が10**9なので9
print((len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= N)])))