Problem:
 Score : 200 points    Problem Statement Tak performed the following action N times: rolling two dice.
The result of the i -th roll is D_{i,1} and D_{i,2} .  Check if doublets occurred at least three times in a row.
Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2} , D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.      Constraints  3 \leq N \leq 100  1\leq D_{i,j} \leq 6  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  D_{1,1}  D_{1,2}  \vdots  D_{N,1}  D_{N,2}       Output Print Yes if doublets occurred at least three times in a row. Print No otherwise.        Sample Input 1 5
1 2
6 6
4 4
3 3
3 2      Sample Output 1 Yes  From the second roll to the fourth roll, three doublets occurred in a row.       Sample Input 2 5
1 1
2 2
3 4
5 5
6 6      Sample Output 2 No       Sample Input 3 6
1 1
2 2
3 3
4 4
5 5
6 6      Sample Output 3 Yes

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]



def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
data = ILL(N)

flag = []
for a,b in data:
  if a == b:
    flag.append(1)
  else:
    flag.append(0)
    
for i in range(N-2):
  if flag[i]+flag[i+1]+flag[i+2]==3:
    print("Yes")
    exit()
print("No")

Solution (Python):
N = int(input())
Darray = [list(map(int, input().split())) for _ in range(N)]

tmp = []
for D in Darray:
    if(D[0] == D[1]):
        tmp.append(1)
    
    else:
        tmp.append(0)

for i in range(N-2):
    if(tmp[i] + tmp[i+1] + tmp[i+2] == 3):
        print("Yes")
        exit()

print("No")

Solution (Python):
n = int(input())

zoro = 0

for i in range(n):
  d1, d2 = map(int, input().split())
  if d1 == d2:
    zoro += 1
  else:
    zoro = 0
  if zoro == 3:
    print("Yes")
    exit()
else:
  print("No")

Solution (Python):

N = int(input())
x =[list(map(int, input().split())) for i in range(N)]
for i in range(N-2):
    if x[i][0] == x[i][1] and x[i+1][0] == x[i+1][1] and x[i+2][0] == x[i+2][1]:
        print("Yes")
        exit()
    else:
        pass
print("No")

Solution (Python):
n = int(input())

flg = False
cnt = 0
for i in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    
    if cnt == 3:
        flg = True

if flg:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
c = 0
for i in range(n):
  d = list(map(int,input().split()))
  if d[0] == d[1]:
    c += 1
  else:
    c = 0
  if c == 3:
    print("Yes")
    exit()
  if i == n-1:
    print("No")

Solution (Python):
def main():

    N = int(input())
    cnt = 0
    ans = "No"

    for i in range(N):
        D1, D2 = map(int, input().split())
        if D1 == D2:
            cnt = cnt + 1
        else:
            cnt = 0

        if cnt == 3:
            ans = "Yes"

    print(ans)

main()

Solution (Python):

import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]










n = I()
cnt = 0
b = 0
num = 0
for i in range(n):
    d1,d2 = MI()
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        b = 1
        break
if b == 1:
    print("Yes")
else:
    print("No")

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    D = [tuple(map(int, input().split())) for _ in [0] * N]  

    n = 0
    for d1, d2 in D:
        if d1 == d2:
            n += 1
        else:
            n = 0
        if n > 2:
            print('Yes')
            break
    else:
        print('No')


main()

Solution (Python):
n = int(input())

c = 0
for i in range(n):
    a,b = map(int,input().split())
    if a == b:
        c += 1
    else:
        c = 0
    if c >= 3:
        print("Yes")
        exit()

print("No")

Solution (Python):
N=int(input())
count=0
for i in range(N):
    A,B=map(int,input().split())
    if A==B:
       count+=1
       if count==3:
           print("Yes")
           exit()
    else:
        count=0
    
    
print("No")

Solution (Python):
n = int(input())

cnt = 0
for i in range(n):
    d1,d2 = map(int,input().split())
    if d1 == d2:
        cnt += 1
        if cnt == 3:
            print("Yes")
            exit()
    else:
        cnt = 0
else:
    print("No")

Solution (Python):
n = int(input())

def find(d):
    pp = False
    p = False
    for d1, d2 in d:
        now = (d1 == d2)
        if pp and p and now:
            return True
        pp = p
        p = now

    return False

d = list()
for i in range(n):
    d1, d2 = map(int, input().split())
    d.append((d1, d2))

if find(d):
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
tem = 0
Flag = False

for i in range(N):
    D1,D2 = map(int,input().split())
    
    if D1 == D2:
        tem += 1
        if tem == 3:
            Flag = True
    else:
        tem = 0


if Flag:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
d = list(list(map(int, input().split())) for _ in range(n))

for i in range(2):
    for j in range(n - 2):
        if d[j][0] == d[j][1] and d[j + 1][0] == d[j + 1][1] and d[j + 2][0] == d[j + 2][1]:
            print("Yes")
            exit()
print("No")

Solution (Python):





N = int(input())




D = [list(map(int, input().split())) for _ in range(N)]



zoro = 0

for d1, d2 in D:
    if d1 == d2:
        zoro += 1
    else:
        zoro = 0

    if zoro == 3:
        print("Yes")
        exit()

print("No")

Solution (Python):
n=int(input())
d=[list(map(int,input().split())) for i 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")

Solution (Python):
N = int(input())
count = 0
max_count = 0
for _ in range(N):
    a, b = map(int, input().split())
    if a == b:
        count += 1
        max_count = max(max_count, count) 
    else:
        count = 0
print('Yes' if max_count > 2 else 'No')

Solution (Python):




n = int(input())


sai1 = []
sai2 = []
for i in range(n):
    _sai1, _sai2 = map(int, input().split(' '))
    sai1.append(_sai1)
    sai2.append(_sai2)

z_cnt = 0
for i in range(n):
    if sai1[i] == sai2[i]:
        z_cnt += 1
    else:
        z_cnt = 0
    if z_cnt == 3:
        print('Yes')
        exit()
print('No')

Solution (Python):
n = int(input())
dice = []
for _ in range(n):
    num = list(map(int, input().split()))
    dice.append(num)

cnt = 0
for die in dice:
    if die[0] == die[1]:
        cnt += 1
        if 3 <= cnt:
            break
    else:
        cnt = 0

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

Solution (Python):
N = int(input())
a = 0
ans = 'No'
for i in range(N):
    x, y = map(int, input().split())
    if x == y:
        a += 1
    else:
        a = 0
    if a == 3:
        ans = 'Yes'
        break
print(ans)

Solution (Python):
b=int(input())
count=0
for i in range(b) :
  m, n = map(int, input().split())
  if count>=3 :
    break
  elif m==n :
    count+=1
  else :
    count=0
if count>=3 :
  print('Yes')
else :
  print('No')

Solution (Python):


N = int(input())
count = max_count = 0

for _ in range(N):
    d1, d2 = map(int, input().split())

    if d1 == d2:
        count += 1

        if count > max_count:
            max_count = count

    else:
        count = 0

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

Solution (Python):
n = int(input())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]

same = 0

for i in range(n):
  if x[i] == y[i]:
    same += 1
  else:
    same = 0
  if same >= 3:
    print("Yes")
    exit()
    
print("No")

Solution (Python):
def main():
    N = int(input())
    D = [list(map(int,input().split())) for i in range(N)]
    cnt = 0
    for i in range(N):
        if D[i][0] == D[i][1]:
            cnt += 1
            if cnt == 3:
                return 'Yes'
        else:
            cnt = 0
    return 'No'

print(main())

Solution (Python):
n = int(input())
cnt = 0
flag = False
for _ in range(n):
    a, b = map(int, input().split())
    if a == b:
        cnt += 1
    else:
        cnt = 0
    
    if cnt == 3:
        flag = True
        break

if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
s = ""
for i in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2 :
        s += 'y'
    else :
        s += 'n'
if "yyy" in s :
    print('Yes')
else :
    print('No')

Solution (Python):

import sys,io,os,time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline



n = int(input())
arr = []
for i in range(n):
	arr.append(list(map(int , input().split())))
f = 0
for i in range(n-3):
	if arr[i][0] == arr[i][1] and arr[i+1][0] == arr[i+1][1] and arr[i+2][0] == arr[i+2][1] :
		f = 1
i = 0
if arr[i][0] == arr[i][1] and arr[i+1][0] == arr[i+1][1] and arr[i+2][0] == arr[i+2][1] :
		f = 1
if f:
	print("Yes")
else:
	print("No")
	








'''


import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)



threading.Thread(target=solve).start()
'''

Solution (Python):
c=0
ans='No'
for _ in range(int(input())):
    d1,d2=map(int, input().split())
    if d1==d2:
        c+=1
    else:
        c=0
    if c==3:
        ans='Yes'
print(ans)

Solution (Python):
N = int(input())

count = 0
for _ in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        count += 1
    else:
        count = 0
    if count == 3:
        print('Yes')
        break
else:
    print('No')

Solution (Python):
n = int(input())

cnt = 0

for i in range(n):
    x, y = map(int, input().split())
    if x == y:
        cnt += 1
        
    else :
        cnt = 0
    if cnt == 3:
        print('Yes')
        break

if cnt<3:
    print('No')

Solution (Python):
N = int(input())

same = []
ok = 0
max_ok = 0
for i in range(N):
    x, y = input().split()
    if x == y:
        ok+=1
    else:
        max_ok = max(max_ok, ok)
        ok = 0
max_ok = max(max_ok, ok)

if max_ok >= 3:
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())

cnt_ = 0
for i in range(N):
  a, b = input().split()
  if a == b:
    cnt_ += 1
    if cnt_ == 3:
      break
  else:
    cnt_ = 0
if cnt_ == 3:
  print("Yes")
else:
  print("No")

Solution (Python):
N = int(input())

count = 0
for i in range(N):
  d1,d2 = map(int,input().split())
  if(d1==d2):
    count = count + 1
  else:
    count = 0
  if(count == 3):break
if(count == 3):
  print("Yes")
else:
  print("No")

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


def solve(N: int, D: "List[List[int]]"):
    c = 0
    for (x,y) in D:
        if x == y:
            c += 1
            if c >= 3:
                return 'Yes'
        else:
            c = 0
    return 'No'


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    D = [[int(next(tokens)) for _ in range(2)] for _ in range(N)]  
    print(solve(N, D))

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
d1,d2 = [],[]
for _ in range(n):
    a,b = map(int,input().split())
    d1.append(a)
    d2.append(b)
check = True
for i in range(2,n):
    if d1[i-2] == d2[i-2] and d1[i-1] == d2[i-1] and d1[i] == d2[i]:
        print("Yes")
        check = False
        break
if check:
    print("No")

Solution (Python):

import sys
import numpy as np

YES = "Yes"  
NO = "No"  


def solve(N: int, D: "List[List[int]]"):
    ans = False
    c = 0
    for i in range(N):
        if D[i][0]==D[i][1]:
            c += 1
            if c == 3:
                ans = True
        else:
            c = 0

    if ans:
        print(YES)
    else:
        print(NO)
    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))  
    D = [[int(next(tokens)) for _ in range(2)] for _ in range(N)]  
    solve(N, D)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
i=0
ans = 'No'
for _ in range(N):
  a,b = map(int, input().split())
  if a==b:
    i += 1
  else:
    i = 0

  if i == 3:
    ans = 'Yes'

print(ans)

Solution (Python):
n =int(input())
cnt = 0
flag = False
for i in range(n):
    d = list(map(int,input().split()))
    if d[0] == d[1]:
        cnt += 1
        if cnt == 3:
            flag = True
    else:
        cnt = 0

print(['No','Yes'][flag])

Solution (Python):
n=int(input()) 
cnt=0
ans=0

for i in range(n):
    a,b=map(int, input().split())
    if a==b:
        cnt+=1
        if ans < cnt:
            ans = cnt
    else:
        cnt=0

if ans >=3:
    print('Yes')
else:
    print('No')

Solution (Python):
N=int(input())
c=0
for i in range(N):
  D=list(map(int,input().split()))
  if D[0]==D[1]:
    c+=1
  else:
    c=0
    
  if c==3:
    print('Yes')
    exit()
print('No')

Solution (Python):
def solve(D):
    ans = []
    tmp = 0
    for d in D:
        if d[0] == d[1]:
            tmp += 1
        else:
            ans.append(tmp)
            tmp = 0
    ans.append(tmp)

    return 'Yes' if max(ans) >= 3 else 'No'


if __name__ == "__main__":
    N = int(input())
    D = [list(map(int, input().split())) for _ in range(N)]
    print(solve(D))

Solution (Python):
n = int(input())

count = 0
is_match = False
for i in range(n):
    d = [int(e) for e in input().split()]
    
    if d[0] == d[1]:
        count += 1
    else:
        count = 0
    
    if count == 3:
        is_match = True
        break

if is_match:
    print('Yes')
else:
    print('No')

Solution (Python):
n=int(input())
A=list()
for i in range(n):
    a,b=map(int,input().split())
    c=abs(a-b)
    A.append(c)
for i in range(n-2):
    p,q,r=A[i],A[i+1],A[i+2]
    s=p+q+r
    if s==0:
        print('Yes')
        break
else:
    print('No')

Solution (Python):
n=int(input())
d=[list(map(int, input().split())) for _ in range(n)]
ans=False
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]:
        ans=True
        break
if ans:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
ans1 = False
ans2 = False
ans3 = False
for i in range(N):
  D1, D2 = map(int, input().split())
  if D1 == D2 and ans1 == False:
    ans1 = True
  elif D1 == D2 and ans1 == True and ans2 == False:
    ans2 = True
  elif D1 == D2 and ans1 == True and ans2 == True and ans3 == False:
    ans3 = True
    print("Yes")
    exit()
  elif D1 != D2:
    ans1 = False
    ans2 = False
    ans3 = False
print("No")

Solution (Python):
N=int(input())
dd=[list(map(int,input().split())) for i in range(N)]
count=0
last=0
for i in range(N):
    d1=dd[i][0]
    d2=dd[i][1]
    if d1==d2:
        count+=1
        if count==3:
            print('Yes')
            exit()
    else:
        count=0

print('No')

Solution (Python):
def main():
    n = int(input())
    D = [list(map(int,input().split())) for _ in range(n)]

    ans = [False]*n
    for i in range(n):
        ans[i] = D[i][0] == D[i][1]
    for i in range(2,n):
        if ans[i] and ans[i - 1] and ans[i - 2]:
            print("Yes")
            return
    print("No")
    return

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
x = 0
for i in range(n):
  a,b = map(int,input().split())
  if a == b:
    x += 1
  else:
    x = 0
  if x == 3:
    print("Yes")
    exit()
  elif i == n-1:
    print("No")

Solution (Python):
import sys, math
import io, os

from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal


mod = int(1e9) + 7
INF=float('inf')

ans=0
cnt=0
for i in range(int(data())):
    d1,d2=mdata()
    if d1==d2:
        cnt+=1
    else:
        ans = max(ans, cnt)
        cnt=0
ans=max(ans,cnt)
if ans>2:
    out("Yes")
else:
    out("No")

Solution (Python):
v = int(input())

count = 0
res = False
for i in range(v):
    s = input().split(' ')
    if s[0] == s[1]:
        count = count + 1
        if count >= 3:
            res = True
    else:
        count = 0
print('Yes' if res else 'No')

Solution (Python):
import math
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
import time

import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
from numba import jit


def main():
    N = int(input())
    count=0
    ans=False
    for i in range(N):
        a,b = map(int,input().split())
        if a==b:
            count += 1
        else:
            count=0
        if count >=3:
            ans=True
    print("Yes" if ans else "No")

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
count = 0
ans = 0
for i in range(n):
  a, b = map(int,input().split())
  if (a == b):
    count = count + 1
    if (count == 3):
      ans = 1
  else:
    count = 0
if (ans == 1):
  print("Yes")
else:
  print("No")

Solution (Python):

a = int(input())
cnt = 0

ans = 'No'

for i in range(a):
    L = list(map(int,input().split()))
    if L[0] == L[1]:
        cnt += 1
    else:
        cnt = 0
    
    if cnt >= 3:
        ans = 'Yes'
        break

print(ans)

Solution (Python):
import math
import collections
from sys import exit
from itertools import product

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
d = [li() for _ in range(n)]

flag = 0
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')
        exit()
print('No')

Solution (Python):
N = int(input())
cnt=0
for _ in range(N):
  a,b = map(int,input().split())
  if a==b:
    cnt+=1
  else:
    cnt=0
  if cnt==3:
    print("Yes")
    break
if cnt < 3:
  print("No")

Solution (Python):
import sys

n = int(input())

n_concecutive = 0

for _ in range(n):
    d1, d2 = map(lambda x: int(x), input().split())
    if d1 == d2:
        n_concecutive += 1
        if n_concecutive >= 3:
            print('Yes')
            sys.exit()
    else:
        n_concecutive = 0
print('No')

Solution (Python):
N = int(input())
ans = False
count = 0
for _ in range(N):
    a, b = [int(a) for a in input().split()]
    if a==b:
        count += 1
        if count == 3:
            ans = True
    else:
        count = 0

if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time


def get_int(): return int(stdin.readline().strip())


def get_tuple(): return map(int, stdin.readline().split())


def get_list(): return list(map(int, stdin.readline().split()))

n = get_int()
ls = []
for _ in range(n):
    x,y = get_tuple()
    ls.append([x,y])

one,two,three = False,False,False
one = True if ls[0][0]==ls[0][1] else False
two = True if ls[1][0]==ls[1][1] else False
three = True if ls[2][0]==ls[2][1] else False
flag = 0
for i in range(3,n):
    one = two; two=three
    three = True if ls[i][0]==ls[i][1] else False
    if one and two and three:
        flag = 1
        break
if one and two and three:
        flag = 1
if flag: print("Yes")
else: print("No")

Solution (Python):
N = int(input())

D_list = []
for i in range(N):
    d1, d2 = map(int, input().split())
    D_list.append([d1, d2])

cnt = 0
for i in range(N):
    if D_list[i][0] == D_list[i][1]:
        cnt += 1
        if cnt == 3:
            print("Yes")
            break
    else:
        cnt = 0
    if i == N-1:
        print("No")

Solution (Python):
n = int(input())
cnt = 0
flg = False
for i in range(n):
  a,b = list(map(int,input().split()))
  if a == b:
    cnt +=1
    if cnt > 2:
      flg = True
  else:
    cnt = 0
if flg:
  print('Yes')
else:
  print('No')

Solution (Python):
N = int(input())
ans = 'No'
cnt = 0
for _ in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        ans = 'Yes'
print(ans)

Solution (Python):
import sys


def solve(result):
    ans = 0
    for d1, d2 in result:
        if d1 == d2:
            ans += 1
            if ans == 3:
                return True
        else:
            ans = 0
    return False


def main():
    input = sys.stdin.buffer.readline
    n = int(input())

    result = []
    for _ in range(n):
        d1, d2 = map(int, input().split())
        result.append((d1, d2))

    print("Yes" if solve(result) else "No")


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
x = 0
ans = 'No'
for i in range(N):
    a, b = map(int, input().split())
    if a == b:
        x += 1
        if x >= 3:
            ans = 'Yes'
            break
    else:
        x = 0

print(ans)

Solution (Python):
cnt = 0
flg = False
for _ in range(int(input())):
    a, b = map(int, input().split())
    if a == b:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        flg = True

print(("No", "Yes")[flg])

Solution (Python):









import os
import sys




def main():
    N = int(input())
    deme = []
    for _ in range(N):
        D = list(map(int, input().split()))
        deme.append(D)
    for i in range(N-2):
        if deme[i][0] == deme[i][1] and \
           deme[i+1][0] == deme[i+1][1] and \
           deme[i+2][0] == deme[i+2][1]:
               print('Yes')
               return
    print('No')


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import itertools

N = int(input())

z = 0
c = 'No'
for i in range(N):
    a, b = map(int, input().split())
    if a == b:
        z += 1
    else:
        z = 0

    if z > 2:
        c = 'Yes'

print(c)

Solution (Python):
n = int(input())

D = []

for i in range(n):
    x, y = map(int, input().split())
    D.append(set([x, y]))

for i in range(1, n - 1):
    if len(D[i - 1]) == 1 and len(D[i]) == 1 and len(D[i + 1]) == 1:
        print('Yes')
        exit()

print('No')

Solution (Python):
def main():
    N = int(input())
    count = 0
    for n in range(N):
        tmp = [int(n) for n in input().split()]
        if tmp[0] == tmp[1]:
            count += 1
        else:
            count = 0
        if count == 3:
            print('Yes')
            return
    print('No')


main()

Solution (Python):
import sys

input_ = sys.stdin.readline


N = int(input_().strip())

rslt = ""
for _ in range(N):
    a, b = [int(x) for x in input_().strip().split(" ")]
    rslt += "Y" if a == b else "N"
print("Yes" if "YYY" in rslt else "No")

Solution (Python):
n = int(input())
c = 0
ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == b:
        c += 1
    else:
        c = 0
    if c >= 3:
        ans += 1
print('Yes' if ans else 'No')

Solution (Python):
n=int(input())
tmp=0
flag=0
for i in range(n):
    x,y=map(int,input().split())
    if(x==y):
        tmp+=1
    else:
        tmp=0
    if(tmp==3):
        flag=1
        break
if(flag):
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())

count = 0

for i in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        count += 1
    else:
        count = 0
    if count == 3:
        print("Yes")
        break
else:
    print("No")

Solution (Python):
n = int(input())
cnt = 0
for i in range(n):
         d1,d2 = map(int,input().split())
         if d1 == d2:
                  cnt += 1
                  if cnt == 3:
                           print("Yes")
                           exit()
         else:
                  cnt = 0
print("No")

Solution (Python):
n=int(input())
zoro=0
for i in range(n):
  d1,d2=map(int,input().split())
  if d1==d2:
    zoro+=1
  else:
    zoro=0
  if zoro==3:
    print('Yes')
    exit()
print('No')

Solution (Python):
n = int(input())

cnt = 0
x = 0
for i in range(n) :
  a, b = map(int, input().split())
  if a == b :
    cnt += 1
  else :
    cnt = 0
  
  if cnt == 3 :
    x += 1

if x >= 1 :
  print("Yes")
else :
  print("No")

Solution (Python):
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]  

for i in range(n):
    if i < n-2:
        if s[i][0] == s[i][1] and s[i+1][0] == s[i+1][1] and s[i+2][0] == s[i+2][1]:
            print('Yes')
            exit()
print('No')

Solution (Python):
N = int(input())
cnt = 0
ans = 0
for i in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
        ans = max(ans, cnt)
    else:
        cnt = 0

if ans >= 3:
    print('Yes')
else:
    print('No')

Solution (Python):
def II(): return int(input())
def LMI(): return list(map(int,input().split()))

n=II()
dice=[LMI() for _ in range(n)]
flag=0
for i in range(n-2):
    if dice[i][0]==dice[i][1]:
        if dice[i+1][0]==dice[i+1][1]:
            if dice[i+2][0]==dice[i+2][1]:
                flag+=1

if flag>0:
    print("Yes")
else:
    print("No")

Solution (Python):
N=int(input())
check=0
Flag=False
for i in range(N):
    d_1,d_2=map(int,input().split())
    if d_1==d_2:
        check+=1
    else:
        check=0
    if check==3:
        Flag=True
if Flag:
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())

ans = 0
tmp = 0
for i in range(N):
    d,e = map(int,input().split())
    if d == e:
        tmp += 1
    else:
        tmp = 0
    ans = max(ans,tmp)

print("Yes" if ans >= 3 else "No")

Solution (Python):
n = int(input())

cnt = 0
ans = "No"
for _ in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        ans = "Yes"
print(ans)