CodeEff/ECCO huggingface dataset:
# Original solution
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
r = 1000000001

for line in file_input:
    x1, y1, x2, y2 = (list(map(int, line.split())))
    if y1 == y2:
        EP.append((min(x1, x2), l, y1))
        EP.append((max(x1, x2), r, y1))
    else:
        EP.append((x1, min(y1, y2), max(y1, y2)))

# Sweep
import bisect

EP.sort()
BT = []
cnt = 0

for p in EP:
    y1 = p[1]
    if y1 == l:
        bisect.insort(BT, p[2])
    elif y1 == r:
        i = bisect.bisect_left(BT, p[2])
        BT.pop(i)
    else:
        cnt += bisect.bisect(BT, p[2]) - bisect.bisect_left(BT, y1)

# Output
print(cnt)

# Optimized solution
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001

for line in file_input:
    x1, y1, x2, y2 = (list(map(int, line.split())))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))

# Sweep
import bisect

EP.sort()
BT = []
cnt = 0

for p in EP:
    x1 = p[1]
    if x1 == l:
        bisect.insort(BT, p[2])
    elif x1 == u:
        i = bisect.bisect_left(BT, p[2])
        BT.pop(i)
    else:
        cnt += bisect.bisect(BT, p[2]) - bisect.bisect_left(BT, x1)

# Output
print(cnt)
# Original solution
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001

for line in file_input:
    x1, y1, x2, y2 = (list(map(int, line.split())))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))

# Sweep
import bisect

EP.sort()
BT = []
cnt = 0

for p in EP:
    x1 = p[1]
    if x1 == l:
        bisect.insort(BT, p[2])
    elif x1 == u:
        i = bisect.bisect_left(BT, p[2])
        BT.pop(i)
    else:
        cnt += bisect.bisect(BT, p[2]) - bisect.bisect_left(BT, x1)

# Output
print(cnt)

# Optimized solution
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001

for line in file_input:
    x1, y1, x2, y2 = (list(map(int, line.split())))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))

# Sweep
import bisect

EP.sort()
BT = []
cnt = 0

for p in EP:
    e = p[1]
    if e == l:
        bisect.insort(BT, p[2])
    elif e == u:
        i = bisect.bisect_left(BT, p[2])
        BT.pop(i)
    else:
        cnt += bisect.bisect(BT, p[2]) - bisect.bisect_left(BT, e)

# Output
print(cnt)
# Original solution
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001
vs_x = set()

for line in file_input:
    x1, y1, x2, y2 = (list(map(int, line.split())))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
        vs_x.add(x1)
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))

vs_x = sorted(vs_x)

# Segment Tree(Range Sum Query)
import math

m = 2 ** math.ceil(math.log(len(vs_x), 2))
ST = [0] * (2 * m - 1)

def switch(i):
    i += m - 1
    if ST[i]:
        d = -1
    else:
        d = 1
    ST[i] += d

    while i > 0:
        i = (i - 1) // 2
        ST[i] += d

def get_sum(s, t, k, l, r):
    if r < s or t < l:
        return 0
    elif s <= l and r <= t:
        return ST[k]
    else:
        mid = (l + r) // 2
        l_sum = get_sum(s, t, k * 2 + 1, l, mid)
        r_sum = get_sum(s, t, k * 2 + 2, mid + 1, r)
        return l_sum + r_sum

# Sweep
import bisect

EP.sort()
cnt = 0

for p in EP:
    e = p[1]
    if e == l or e == u:
        vs_i = bisect.bisect_left(vs_x, p[2])
        switch(vs_i)
    else:
        l_x = bisect.bisect_left(vs_x, e)
        r_x = bisect.bisect(vs_x, p[2]) - 1
        cnt += get_sum(l_x, r_x, 0, 0, m - 1)

# Output
print(cnt)

# Optimized solution
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001
vs_x = set()

for line in file_input:
    x1, y1, x2, y2 = (list(map(int, line.split())))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
        vs_x.add(x1)
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))

vs_x = sorted(vs_x)

# Binary Indexed Tree
class BinaryIndexedTree:
    def __init__(self, n):
        self.data = [0] * (n + 1)
        self.num = n

    def switch(self, i, d):
        while  i <= self.num:
            self.data[i] += d
            i += i & -i

    def _sum(self, i):
        s = 0
        while i:
            s += self.data[i]
            i -= i & -i
        return s

    def seg_sum(self, a, b):
        return self._sum(b) - self._sum(a - 1)

# Sweep
import bisect

EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
cnt = 0

for p in EP:
    e = p[1]
    if e == l:
        vx = bisect.bisect(vs_x, p[2])
        BIT.switch(vx, 1)
    elif e == u:
        vx = bisect.bisect(vs_x, p[2])
        BIT.switch(vx, -1)
    else:
        l_x = bisect.bisect_left(vs_x, e) + 1
        r_x = bisect.bisect(vs_x, p[2])
        cnt += BIT.seg_sum(l_x, r_x)

# Output
print(cnt)
# Original solution
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001
vs_x = set()

for line in file_input:
    x1, y1, x2, y2 = (list(map(int, line.split())))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
        vs_x.add(x1)
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))

# Binary Indexed Tree
class BinaryIndexedTree:
    def __init__(self, n):
        self.data = [0] * (n + 1)
        self.num = n

    def switch(self, i, d):
        while  i <= self.num:
            self.data[i] += d
            i += i & -i

    def _sum(self, i):
        s = 0
        while i:
            s += self.data[i]
            i -= i & -i
        return s

    def seg_sum(self, a, b):
        return self._sum(b) - self._sum(a - 1)

# Sweep
import bisect

EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
vs_x = [l] + sorted(vs_x)
d_vs_x = {e: i for i, e in enumerate(vs_x)}
cnt = 0

for p in EP:
    e = p[1]
    if e == l:
        BIT.switch(d_vs_x[p[2]], 1)
    elif e == u:
        BIT.switch(d_vs_x[p[2]], -1)
    else:
        l_x = bisect.bisect_left(vs_x, e)
        r_x = bisect.bisect(vs_x, p[2]) - 1
        cnt += BIT.seg_sum(l_x, r_x)

# Output
print(cnt)

# Optimized solution
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001
vs_x = set()
h_num = 0

for line in file_input:
    x1, y1, x2, y2 = (list(map(int, line.split())))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
        vs_x.add(x1)
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))
        h_num += 1

# Binary Indexed Tree
class BinaryIndexedTree:
    def __init__(self, n):
        self.data = [0] * (n + 1)
        self.num = n

    def switch(self, i, d):
        while  i <= self.num:
            self.data[i] += d
            i += i & -i

    def _sum(self, i):
        s = 0
        while i:
            s += self.data[i]
            i -= i & -i
        return s

    def seg_sum(self, a, b):
        return self._sum(b) - self._sum(a - 1)

# Sweep
import bisect

EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
vs_x = [l] + sorted(vs_x)
d_vs_x = {e: i for i, e in enumerate(vs_x)}
cnt = 0

for p in EP:
    e = p[1]
    if e == l:
        BIT.switch(d_vs_x[p[2]], 1)
    elif e == u:
        BIT.switch(d_vs_x[p[2]], -1)
    else:
        l_x = bisect.bisect_left(vs_x, e)
        r_x = bisect.bisect(vs_x, p[2]) - 1
        cnt += BIT.seg_sum(l_x, r_x)
        h_num -= 1
    if h_num == 0:
        break

# Output
print(cnt)
# Original solution
import bisect


def memoize(f):
    cache = {}

    def func(x):
        if x not in cache:
            ret = cache[x] = f(x)
            return ret
        return cache[x]

    return func


@memoize
def get_bisect(y):
    return bisect.bisect(vy, (y, float('-inf')))


n = int(eval(input()))
vx, vy = [], []
for _ in range(n):
    x1, y1, x2, y2 = list(map(int, input().split()))
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        vx.append((x1, y1, y2))
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        vy.append((y1, x1, x2))
vy.sort()

ans = 0

for x, y1, y2 in vx:
    it1, it2 = get_bisect(y1), get_bisect(y2 + 1)
    ans += sum(x1 <= x <= x2 for y, x1, x2 in vy[it1:it2])

print(ans)

# Optimized solution
import bisect

n = int(eval(input()))
vx, vy = [], []
for _ in range(n):
    x1, y1, x2, y2 = list(map(int, input().split()))
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        vx.append((x1, y1, y2))
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        vy.append((y1, x1, x2))
vy.sort()

ans = 0
cache = {}

for x, y1, y2 in vx:
    y2 += 1
    if y1 not in cache:
        it1 = cache[y1] = bisect.bisect(vy, (y1,))
    else:
        it1 = cache[y1]
    if y2 not in cache:
        it2 = cache[y2] = bisect.bisect(vy, (y2,))
    else:
        it2 = cache[y2]
    ans += sum(x1 <= x <= x2 for y, x1, x2 in vy[it1:it2])

print(ans)
# Original solution
import bisect

n = int(eval(input()))
vx, vy = [], []
for _ in range(n):
    x1, y1, x2, y2 = list(map(int, input().split()))
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        vx.append((x1, y1, y2))
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        vy.append((y1, x1, x2))
vy.sort()

ans = 0
cache = {}

for x, y1, y2 in vx:
    y2 += 1
    if y1 not in cache:
        it1 = cache[y1] = bisect.bisect(vy, (y1,))
    else:
        it1 = cache[y1]
    if y2 not in cache:
        it2 = cache[y2] = bisect.bisect(vy, (y2,))
    else:
        it2 = cache[y2]
    ans += sum(x1 <= x <= x2 for y, x1, x2 in vy[it1:it2])

print(ans)

# Optimized solution
import bisect


def memoize(f):
    cache = {}

    def func(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]

    return func


@memoize
def get_bisect(y):
    return bisect.bisect(vy, (y,))


n = int(eval(input()))
vx, vy = [], []
for _ in range(n):
    x1, y1, x2, y2 = list(map(int, input().split()))
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        vx.append((x1, y1, y2))
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        vy.append((y1, x1, x2))
vy.sort()

ans = 0

for x, y1, y2 in vx:
    it1, it2 = get_bisect(y1), get_bisect(y2 + 1)
    ans += sum(1 for y, x1, x2 in vy[it1:it2] if x1 <= x <= x2)

print(ans)
# Original solution
#線分交差問題

import bisect

class BIT:
    def __init__(self, n):
        self.tree = [0]*(n+1)
        self.n = n
    
    def add(self, i, v):
        while i <= self.n:
            self.tree[i] += v
            i += i & -i
        
    
    def _sum(self, i):
        ret = 0
        while i:
            ret += self.tree[i]
            i -= i & -i
        return ret
    
    def sum(self, l, h):
        return self._sum(h) - self._sum(l-1)
    
n = int(eval(input()))
vx = []
xs = set()
for _ in range(n):
    x1, y1, x2, y2 = list(map(int, input().split()))
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        vx.append((y1, float('-inf'),x1))
        vx.append((y2, float('inf'),x2))
        xs.add(x1)
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        vx.append((y1, x1, x2))
vx.sort()

bit = BIT(len(xs))
xs = [float('-inf')] + sorted(xs)
ix = {v: i for i, v in enumerate(xs)}
ans = 0

for y, j, x2 in vx:
    if j == float('-inf'):
        bit.add(ix[x2],1)
    elif j == float('inf'):
        bit.add(xs.index(x2), -1)
    else:
        l = bisect.bisect_left(xs, j)
        r = bisect.bisect(xs, x2) - 1
        ans += bit.sum(l, r)
        
print(ans)



# Optimized solution
#線分交差問題

import bisect

class BIT:
    def __init__(self, n):
        self.tree = [0]*(n+1)
        self.n = n
    
    def add(self, i, v):
        while i <= self.n:
            self.tree[i] += v
            i += i & -i
        
    
    def _sum(self, i):
        ret = 0
        while i:
            ret += self.tree[i]
            i -= i & -i
        return ret
    
    def sum(self, l, h):
        return self._sum(h) - self._sum(l-1)
    
n = int(eval(input()))
vx = []
xs = set()
for _ in range(n):
    x1, y1, x2, y2 = list(map(int, input().split()))
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        vx.append((y1, float('-inf'),x1))
        vx.append((y2, float('inf'),x2))
        xs.add(x1)
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        vx.append((y1, x1, x2))
vx.sort()

bit = BIT(len(xs))
xs = [float('-inf')] + sorted(xs)
ix = {v: i for i, v in enumerate(xs)}
ans = 0

for y, j, x2 in vx:
    if j == float('-inf'):
        bit.add(ix[x2],1)
    elif j == float('inf'):
        bit.add(ix[x2], -1)
    else:
        l = bisect.bisect_left(xs, j)
        r = bisect.bisect(xs, x2) - 1
        ans += bit.sum(l, r)
        
print(ans)
# Original solution
from itertools import cycle

INITIALIZE = 32

while True:

    input_count = int(eval(input()))

    if input_count == 0:
        break

    get_list = [int(item) for item in input().split(" ")]

    ohajiki = INITIALIZE
    output = []

    for get_count in cycle(get_list):

        ohajiki -= (ohajiki - 1) % 5
        output.append(ohajiki)

        if get_count < ohajiki:
            ohajiki -= get_count
            output.append(ohajiki)
        else:
            output.append(0)
            break

    output = [str(item) for item in output]
    print(("\n".join(output)))



# Optimized solution
from itertools import cycle

INITIALIZE = 32

while True:

    input_count = int(eval(input()))

    if input_count == 0:
        break

    get_list = [int(item) for item in input().split(" ")]

    ohajiki = INITIALIZE
    output = []

    for get_count in cycle(get_list):

        ohajiki -= (ohajiki - 1) % 5
        print(ohajiki)

        if get_count < ohajiki:
            ohajiki -= get_count
            print(ohajiki)
        else:
            print((0))
            break
# Original solution
def check(y,x):
    if 0<=y<=h-1 and 0<=x<=w-1:
        return True
    return False

h,w=list(map(int,input().split()))
g=[list(map(int,input().split())) for _ in range(h)]
pos=[-1]*(h*w)
for i in range(h):
    for j in range(w):
        pos[g[i][j]-1]=[i,j]

dy=(1,0,-1,0)
dx=(0,1,0,-1)
stop=[set() for _ in range(h*w)]
ans=0
for i in range(h*w):
    y,x=pos[i]
    for j in range(4):
        ny=y+dy[j];nx=x+dx[j]
        if check(ny,nx):
            if g[ny][nx]<g[y][x]:
                for k in list(stop[g[ny][nx]-1]):
                    stop[i].add(k)
    cnt=len(stop[i])
    if cnt>=2:
        ans+=1
    elif cnt==0:
        stop[i].add(g[y][x])

print(ans)

# Optimized solution
def check(y,x):
    if 0<=y<=h-1 and 0<=x<=w-1:
        return True
    return False

h,w=list(map(int,input().split()))
g=[list(map(int,input().split())) for _ in range(h)]
pos=[-1]*(h*w)
for i in range(h):
    for j in range(w):
        pos[g[i][j]-1]=[i,j]

dy=(1,0,-1,0)
dx=(0,1,0,-1)
stop=[set() for _ in range(h*w)]
ans=0
for i in range(h*w):
    y,x=pos[i]
    for j in range(4):
        ny=y+dy[j];nx=x+dx[j]
        if check(ny,nx):
            if g[ny][nx]<g[y][x]:
                stop[i]=stop[i]|stop[g[ny][nx]-1]
    cnt=len(stop[i])
    if cnt>=2:
        ans+=1
    elif cnt==0:
        stop[i].add(g[y][x])

print(ans)
# Original solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
D = [tuple(MI()) for _ in range(N)]
for i in range(N-2):
    if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]:
        print('Yes')
        break
else:
    print('No')


# Optimized solution
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))


N = I()
D = [0]*N
for i in range(N):
    a,b = MI()
    if a == b:
        D[i] = 1

for i in range(N-2):
    if D[i] == D[i+1] == D[i+2] == 1:
        print('Yes')
        break
else:
    print('No')
# Original solution
def judge():
    cnt = 0  # 今何連続でゾロ目が出ているか記録しておきます

    for _ in range(N):
        x, y = list(map(int, input().split()))
        if x == y:
            # ゾロ目ストリークが1増えました
            cnt += 1
        else:
            # ゾロ目ストリークが切れました
            cnt = 0

        if cnt == 3:
            # 3連続になった瞬間、return True していいです
            return True

    # ダメでした
    return False

N = int(eval(input()))

if judge():
    # judge() で Trueが返ってくるとこっちに進みます
    print("Yes")
else:
    # Falseだとこっちです
    print("No")

# Optimized solution
def judge():
    count = 0
    for _ in range(x):
        d1, d2 = list(map(int, input().split()))
        if d1 == d2:
            count += 1
        else:
            count = 0
        
        if count == 3:
            return True

    return False

x = int(eval(input()))

if judge():
    print("Yes")
else:
    print("No")
# Original solution
import sys

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


def main():
    N = int(readline())

    cur = 0
    cnt = 0
    for _ in range(N):
        x, y = list(map(int, readline().split()))
        if x == y:
            cur += 1
        else:
            cur = 0
        cnt = max(cnt, cur)

    if cnt >= 3:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


# Optimized solution
def judge():
    cnt = 0  # 今何連続でゾロ目が出ているか記録しておきます

    for _ in range(N):
        x, y = list(map(int, input().split()))
        if x == y:
            # ゾロ目ストリークが1増えました
            cnt += 1
        else:
            # ゾロ目ストリークが切れました
            cnt = 0

        if cnt == 3:
            # 3連続になった瞬間、return True していいです
            return True
    
    # ダメでした
    return False

N = int(eval(input()))

if judge():
    print("Yes")
else:
    print("No")
# Original solution
n=int(eval(input())) 
idx=[] 
c=0 
for i in range(n):
	x,y=list(map(int,input().split())) 
	if x==y:
		idx.append(c) 
	c+=1  
if len(idx)<3:
	print('No') 
else:
	flag=False 
	#print(idx)
	for i in range(len(idx)-2): 
		if idx[i]-idx[i+1]==-1 and idx[i+1]-idx[i+2]==-1:
			flag=True  
			break 
	dd={False:'No',True:'Yes'}
	print((dd[flag]))









# Optimized solution
import sys
def main():
	n=int(eval(input())) 
	idx=[] 
	c=0 
	for i in range(n):
		x,y=list(map(int,input().split())) 
		if x==y:
			idx.append(c) 
		c+=1  
	if len(idx)<3:
		print('No') 
	else:
		flag=False 
		#print(idx)
		for i in range(len(idx)-2): 
			if idx[i]-idx[i+1]==-1 and idx[i+1]-idx[i+2]==-1:
				flag=True  
				break 
		dd={False:'No',True:'Yes'}
		print((dd[flag]))
 
try:
	sys.stdin = open('INP01.txt', 'r')  

	# Printing the Output to output.txt file 
	sys.stdout = open('out.txt', 'w')   
	main() 
except:
	main()
# Original solution
n = int(eval(input()))
D = [[*list(map(int, input().split()))] for _ in range(n)]
# print(n)
# print(D)

# ans = True
c = 0
for x, y in D:
    # print(x,y)
    if x==y:c+=1
    else: c = 0
    if c == 3: break

print(('Yes' if c>=3 else 'No'))


# Optimized solution
n = int(eval(input()))
c = 0
for _ in range(n):
    x, y = list(map(int, input().split()))
    if x == y:c += 1
    else: c = 0
    if c == 3: break
print(('No' if c < 3 else 'Yes'))
# Original solution
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    D = [il() for _ in range(N)]

    for i in range(N - 2):
        for j in range(i, i + 3):
            if D[j][0] != D[j][1]: break
        else:
            print('Yes')
            exit()
    else:
        print('No')


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    D = [il() for _ in range(N)]
    for i in range(N - 2):
        for j in range(i, i + 3):
            if D[j][0] != D[j][1]:
                break
        else:
            print('Yes')
            exit()
    else:
        print('No')


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
D = [tuple(map(int, input().split())) for _ in range(N)]
for i in range(N - 2):
    if all(d[0] == d[1] for d in D[i: i + 3]):
        print('Yes')
        exit()
else:
    print('No')


# Optimized solution
def input_array():
	return list(map(int,input().split()))
  
n=int(eval(input()))
D=[input_array() for i in range(n)]

count=0
for d in D:
	if d[0]==d[1]:
		count+=1
	else:
		count=0

	if count==3:
		break
if count==3:
	print("Yes")
else:
	print("No")