CodeEff/ECCO huggingface dataset:
# Original solution

from sys import stdin
class Node:
    def __init__(self, id):
        self.id = id
        self.left = None
        self.right = None
        self.parent = None

def preorder_tree_walk(root):
    print('', root.id, end='')
    if root.left != None:
        preorder_tree_walk(root.left)
    if root.right != None:
        preorder_tree_walk(root.right)

def inorder_tree_walk(root):
    if root.left != None:
        inorder_tree_walk(root.left)
    print('', root.id, end='')
    if root.right != None:
        inorder_tree_walk(root.right)

def insert(root, z):
    y = None
    x = root
    while isinstance(x, Node):
        y = x
        if z.id < x.id:
            x = x.left
        else:
            x = x.right
    z.parent = y

    if y == None:
        root = z
    elif z.id < y.id:
        y.left = z
    else:
        y.right = z
    return root

def find(root, x):
    if root.id == x:
        return True

    if root.id > x:
        if root.left == None:
            return False
        else:
            return find(root.left, x)
    else:
        if root.right == None:
            return False
        else:
            return find(root.right, x)

n = int(input())
root = None
for i in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        num = int(cmd[7:])
        root = insert(root, Node(num))
    elif cmd.startswith('p'):
        inorder_tree_walk(root)
        print()
        preorder_tree_walk(root)
        print()
    else:
        # find
        num = int(cmd[5:])
        if find(root, num):
            print('yes')
        else:
            print('no')

# Optimized solution

from sys import stdin
class Node:
    def __init__(self, id):
        self.id = id
        self.left = None
        self.right = None
        self.parent = None

def preorder_tree_walk(root):
    print('', root.id, end='')
    if root.left != None:
        preorder_tree_walk(root.left)
    if root.right != None:
        preorder_tree_walk(root.right)

def inorder_tree_walk(root):
    if root.left != None:
        inorder_tree_walk(root.left)
    print('', root.id, end='')
    if root.right != None:
        inorder_tree_walk(root.right)

def insert(root, z):
    y = None
    x = root
    while isinstance(x, Node):
        y = x
        if z.id < x.id:
            x = x.left
        else:
            x = x.right
    z.parent = y

    if y == None:
        root = z
    elif z.id < y.id:
        y.left = z
    else:
        y.right = z
    return root

def find(root, x):
    while root != None and x != root.id:
        if x < root.id:
            root = root.left
        else:
            root = root.right
    return root


n = int(input())
root = None
for i in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        num = int(cmd[7:])
        root = insert(root, Node(num))
    elif cmd.startswith('p'):
        inorder_tree_walk(root)
        print()
        preorder_tree_walk(root)
        print()
    else:
        # find
        num = int(cmd[5:])
        if find(root, num) != None:
            print('yes')
        else:
            print('no')
# Original solution
import sys

class Node():
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left, self.right = None, None
        
    def __str__(self):
        return " " + str(self.key)

def insert(z):
    global root
    x, y = root, None
    while x:
        y = x
        if z < x.key:
            x = x.left
        else:
            x = x.right
    
    if y == None:
        root = Node(z)
    elif z < y.key:
        y.left = Node(z)
    else:
        y.right = Node(z)
        
def find(z):
    global root
    x, y = root, None
    while x:
        y = x
        if z < x.key:
            x = x.left
        elif z > x.key:
            x = x.right
        else:
            print("yes")
            return
    print("no")
        
def preorder(x):
    return str(x) + preorder(x.left) + preorder(x.right) if x else ""

def inorder(x):
    return inorder(x.left) + str(x) + inorder(x.right) if x else ""
        
eval(input())
root = None
for s in sys.stdin:
    if s[0] == "p":
        print((inorder(root)))
        print((preorder(root)))
    elif s[0] == "f":
        find(int(s[5:]))
    else:
        insert(int(s[7:]))


# Optimized solution
import sys

class Node():
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left, self.right = None, None

def insert(z):
    global root
    x, y = root, None
    while x:
        y = x
        if z < x.key:
            x = x.left
        else:
            x = x.right
    
    if y == None:
        root = Node(z)
    elif z < y.key:
        y.left = Node(z)
    else:
        y.right = Node(z)
        
def find(z):
    global root
    x, y = root, None
    while x:
        y = x
        if z < x.key:
            x = x.left
        elif z > x.key:
            x = x.right
        else:
            print("yes")
            return
    print("no")
        
def preorder(x):
    return f" {x.key}" + preorder(x.left) + preorder(x.right) if x else ""

def inorder(x):
    return inorder(x.left) + f" {x.key}" + inorder(x.right) if x else ""
        
eval(input())
root = None
for s in sys.stdin:
    if s[0] == "p":
        print((inorder(root)))
        print((preorder(root)))
    elif s[0] == "f":
        find(int(s[5:]))
    else:
        insert(int(s[7:]))
# Original solution
#!/usr/bin/env python

from sys import stdin


class Node(object):
    def __init__(self, key=None):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None


def tree_insert(top, z):
    y = None
    x = top
    while isinstance(x, Node):
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        top = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
    return top


def tree_find(node, key):
    if not node:
        return False
    if node.key == key:
        return True
    return tree_find(node.left, key) or tree_find(node.right, key)


def inorder_walk(node):
    if node.left:
        inorder_walk(node.left)
    print('', node.key, end='')
    if node.right:
        inorder_walk(node.right)


def preorder_walk(node):
    print('', node.key, end='')
    if node.left:
        preorder_walk(node.left)
    if node.right:
        preorder_walk(node.right)


n = int(stdin.readline())
#assert n <= 500000

top = None
for _ in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert -2000000000 <= key <= 2000000000
        top = tree_insert(top, Node(key))
    elif cmd.startswith('f'):
        key = int(cmd[5:])
        r = tree_find(top, key)
        print('yes' if r else 'no')
    else:
        inorder_walk(top)
        print()
        preorder_walk(top)
        print()

# Optimized solution
#!/usr/bin/env python

from sys import stdin


class Node(object):
    def __init__(self, key=None):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None


def tree_insert(top, z):
    y = None
    x = top
    while isinstance(x, Node):
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        top = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
    return top


def tree_find(node, key):
    if not node:
        return False
    if node.key == key:
        return True
    if key < node.key:
        return tree_find(node.left, key)
    return tree_find(node.right, key)


def inorder_walk(node):
    if node.left:
        inorder_walk(node.left)
    print('', node.key, end='')
    if node.right:
        inorder_walk(node.right)


def preorder_walk(node):
    print('', node.key, end='')
    if node.left:
        preorder_walk(node.left)
    if node.right:
        preorder_walk(node.right)


n = int(stdin.readline())
#assert n <= 500000

top = None
for _ in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert -2000000000 <= key <= 2000000000
        top = tree_insert(top, Node(key))
    elif cmd.startswith('f'):
        key = int(cmd[5:])
        r = tree_find(top, key)
        print('yes' if r else 'no')
    else:
        inorder_walk(top)
        print()
        preorder_walk(top)
        print()
# Original solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    x,y,s = list(map(int,input().split()))
    if (x,y,s) == (0,0,0):
        break
    ans = 0
    for i in range(1,s-1):
        for j in range(1,s-i + 1):
            if i*(100+x)//100 + j*(100+x)//100== s:
                ans = max(ans,i*(100+y)//100 + j*(100+y)//100)
    print(ans)

# Optimized solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    x,y,s = list(map(int,input().split()))
    if (x,y,s) == (0,0,0):
        break
    ans = 0
    for i in range(1,s//2 + 1):
        for j in range(1,s-i + 1):
            if i*(100+x)//100 + j*(100+x)//100== s:
                ans = max(ans,i*(100+y)//100 + j*(100+y)//100)
    print(ans)
# Original solution
n,k=list(map(int,input().split()))
d=set(input().split())
a=[]
for i in range(n,10*n):
    if not set(str(i))&set(d):
        print(i)
        exit()

# Optimized solution
n,k=list(map(int,input().split()))
d=set(input().split())
for i in range(n,10*n):
    if not set(str(i))&d:
        print(i)
        exit()
# Original solution
n, k = list(map(int, input().split()))
d = set(range(10)) - set(map(int, input().split()))

i = n
while True:
    if (i >= n) and all(int(k) in d for k in str(i)):
        print(i)
        break
    i += 1


# Optimized solution
n, k = list(map(int, input().split()))
d = set(range(10)) - set(map(int, input().split()))

i = n
while True:
    if (i >= n) and all(int(j) in d for j in str(i)):
        print(i)
        break
    i += 1
# Original solution
s=set(range(10))
n,k,*a=list(map(int,open(0).read().split()))
a=s-set(a) #使っていい数字
for t in range(n,100000):
    if set(list(map(int,list(str(t)))))<=a:
        print(t)
        break

# Optimized solution
x=lambda:input().split()
n,_=x();a=x();n=int(n)
while any(s in set(a)for s in str(n)):n+=1
print(n)
# Original solution
N,K=list(map(int,input().split()))
d=list(map(int,input().split()))

dr=len(d)
for i in range(N,100000):
    s=list(str(i))
    num=0
    for j in d:
        if(str(j) in s):
            break
        else:
            num+=1
    if(num==dr):
        print(i)
        break

# Optimized solution
N,K=list(map(int,input().split()))
D=list(input().split())

for i in range(N,100000):
        ans=True
        for j in str(i):
                if(str(j) in D):
                        ans=False
                        break
        if(ans):
                print(i)
                exit()
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    d = list(map(int, input().rstrip('\n').split()))
    for i in range(n, 10 ** 10):
        t = list(str(i))
        b = True
        for j in range(len(t)):
            if int(t[j]) in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    d = {str(i): 0 for i in list(map(int, input().rstrip('\n').split()))}

    for i in range(n, 10 ** 15):
        t = str(i)
        b = True
        for j in range(len(t)):
            if t[j] in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    slove()
# Original solution
n, k = list(map(int, input().split()))
d = list(input().split())

from itertools import count

for i in count(n):
    s = str(i)
    for bit in s:
        if bit in d:
            break
    else:
        print(i)
        break



# Optimized solution
n,k = list(map(int, input().split()))
d = list(map(int, input().split()))
def v(n):
    for c in map(int, str(n)):
        if (c in d):
            return False
    return True
while (v(n) == False):
    n += 1
print(n)
# Original solution
a,b = list(map(int,input().split(" ")))
ar = list(map(int,input().split(" ")))
while True:
    count = 0
    br = list(str(a))
    for r in br:
        if int(r) in ar:
            count += 1
    if count == 0:
        print(a)
        break
    else:
        a += 1

# Optimized solution
a,b = list(map(int,input().split(" ")))
ar = input().split(" ")
while True:
    count = 0
    for r in ar:
        if r in str(a):
            count += 1
            break
    if count == 0:
        print(a)
        break
    a += 1
# Original solution
#!/usr/bin/env python3
import sys
 
YES = "Yes"  # type: str
NO = "No"  # type: str
 
def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    ret = YES
    if '##' in S[A:C] or '##' in S[B:D]:
        ret = NO
    else:
        if D < C:
            #if S[B - 2:B] == '..' or S[B - 1:B + 1] == '..':
            if not '...' in S[B - 2:D + 1]:
                ret = NO
    print(ret)
    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
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)
 
if __name__ == '__main__':
    main()

# Optimized solution
#!/usr/bin/env python3
import sys
 
YES = "Yes"  # type: str
NO = "No"  # type: str
 
def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    ret = YES
    if '##' in S[A - 1:C] or '##' in S[B - 1:D]:
        ret = NO
    else:
        if D < C:
            #if S[B - 2:B] == '..' or S[B - 1:B + 1] == '..':
            if not '...' in S[B - 2:D + 1]:
                ret = NO
    print(ret)
    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
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)
 
if __name__ == '__main__':
    main()
# Original solution
# 2019-11-22 19:46:21(JST)
import sys


def main():
    n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()]
    s = '#' + sys.stdin.readline().rstrip()

    if '##' in s[a+1:c-1] or '##' in s[b+1:d-1]:
        ans = 'No'
    else:
        if c < d:
            ans = 'Yes'
        else:
            for i in range(b, d+1):
                if s[i-1] == s[i] == s[i+1] == '.':
                    ans = 'Yes'
                    break
            else:
                ans = 'No'
        
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
# 2019-11-22 19:46:21(JST)
import sys


def main():
    n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()]
    s = '#' + sys.stdin.readline().rstrip()

    if '##' in s[a+1:c-1] or '##' in s[b+1:d-1]:
        ans = 'No'
    else:
        if c < d:
            ans = 'Yes'
        else:
            # for i in range(b, d+1):
            #     if s[i-1] == s[i] == s[i+1] == '.':
            #         ans = 'Yes'
            #         break
            if '...' in s[b-1:d+2]:
                ans = 'Yes'
            else:
                ans = 'No'
        
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: int, B: int, C: int, D: int, S: str): 
    if(S[A-1] == '#' or S[B-1] == '#' or  S[C-1] == '#' or S[D-1] == '#'):
        print(NO)
        sys.exit()

    if(S[A-1:C].count('##') == 0 and S[B-1:D].count('##') == 0):
        if(D < C):
            sf = (S[A-1:D+1].count('...'))
            if(sf == 0):
                print(NO)
            
            elif(sf == 1):
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                if(tS[A-1:D+1].count('..b#') == 1):
                    print(NO)
                else:
                    print(YES)
            ######### あとはここだけ考える ####
            elif(sf >= 2):
                # print('Im here!')
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                ptS = tS.rfind('..b#')
                if(ptS == -1):
                    print(YES)
                else:
                    if(tS[ptS+3:D+1].count('...') == 0):
                        # print(tS[ptS:D])
                        print(NO)
                    else:
                        # print(tS[ptS:D])
                        print(YES)
        else: # D > Cの場合
            print(YES)  
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: int, B: int, C: int, D: int, S: str):

    if(S[A-1:C+1].count('##') > 0 or S[B-1:D+1].count('##')):
    # if(S[A:max(C,D)].count('##') > 1):
        print(NO)
        sys.exit()

    if(D < C):
        if(S[B-2:D+1].count('...') <= 0):
            print(NO)
            sys.exit()
        else:
            print(YES)
    else:
        print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python
import bisect
from collections import defaultdict
import math

def judge(start, end, S):
    for i in range(start, end):
        s = S[i:i+2]
        if tuple(s) == ("#", "#"):
            return False
    return True

def main():
    N, A, B, C, D = list(map(int, input().split()))
    S = list(input().strip())

    is_ok = judge(A-1, C-1, S)
    if not is_ok:
        print("No")
        return
    is_ok = judge(B-1, D-1, S)
    if not is_ok:
        print("No")
        return

    if C > D:
        for i in range(B-1, D):
            if S[i] != "#":
                new_S = list(S)
                new_S[i] = "#"
                is_ok = judge(A-1, C-1, new_S)
                if is_ok:
                    print("Yes")
                    return
        print("No")
    else:
        print("Yes")

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python
import bisect
from collections import defaultdict
import math

def judge(start, end, S):
    for i in range(start, end):
        s = S[i:i+2]
        if tuple(s) == ("#", "#"):
            return False
    return True

def main():
    N, A, B, C, D = list(map(int, input().split()))
    S = list(input().strip())

    is_ok = judge(A-1, C-1, S)
    if not is_ok:
        print("No")
        return
    is_ok = judge(B-1, D-1, S)
    if not is_ok:
        print("No")
        return

    if C > D:
        for i in range(B-1, D):
            if S[i] != "#" and S[i-1] != "#" and S[i+1] != "#":
                print("Yes")
                return
        print("No")
    else:
        print("Yes")

if __name__ == '__main__':
    main()
# Original solution
N,A,B,C,D = list(map(int,input().split()))
S = input().strip()
S = "."+S
flag=0
if C<B:
    for i in range(A,C):
        if S[i:i+2]=="##":
            flag=1
            break
    for i in range(B,D):
        if S[i:i+2]=="##":
            flag=1
            break
    if flag==1:
        print("No")
    else:
        print("Yes")
elif B<C<D:
    for i in range(A,D):
        if S[i:i+2]=="##":
            flag=1
            break
    if flag==1:
        print("No")
    else:
        print("Yes")
else:
    for i in range(A,C):
        if S[i:i+2]=="##":
            flag = 1
            break
    if flag==1:
        print("No")
    else:
        flag = 1
        for i in range(B+1,D):
            if S[i]=="#":continue
            if (S[i-1]=="#" and S[i+1]=="#") or (S[i-2:i]=="#." and S[i+1]=="#") or (S[i-1]=="#" and S[i+1:i+3]==".#"):continue
            else:
                flag=0
                break
        if flag==1:
            if S[B+1]=="#" or (S[B-1]=="#" and S[B+1:B+3]==".#"):
                flag=1
            else:
                flag=0
        if flag==1:
            print("No")
        else:
            print("Yes")

# Optimized solution
N,A,B,C,D = list(map(int,input().split()))
S = list(input().strip())
S.insert(0,0)
if C<D:
    flag = 0
    for i in range(A+1,C+1):
        if S[i-1]=="#" and S[i]=="#":
            flag = 1
            break
    for i in range(B+1,D+1):
        if S[i-1]=="#" and S[i]=="#":
            flag = 1
            break
    if flag==0:
        print("Yes")
    else:
        print("No")
else:
    flag = 0
    for i in range(A+1,C+1):
        if S[i]=="#" and S[i-1]=="#":
            flag = 1
            break
    if flag == 0:
        flag1 = 1
        for i in range(B,D+1):
            if i+1<=N and S[i-1]=="." and S[i]=="." and S[i+1]==".":
                flag1 = 0
                break
        if flag1==1:
            flag = 1
    if flag==0:
        print("Yes")
    else:
        print("No")