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



Sample input:
5
1 2
6 6
4 4
3 3
3 2


Sample output:
Yes

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
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
    #print(cnt)
    if cnt == 3:
        flag = True
        break

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
#: Author - Soumya Saurav
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")
	








'''
# Wrap solution for more recursion depth
#submit as python3
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)



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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

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


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))  # type: int
    D = [[int(next(tokens)) for _ in range(2)] for _ in range(N)]  # type: "List[List[int]]"
    print(solve(N, D))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

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


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


# Generated by 1.1.7.1 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
    D = [[int(next(tokens)) for _ in range(2)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, D)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
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
# from itertools import permutations,combinations
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
# from fractions import Fraction
# sys.setrecursionlimit(100000)
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-09-19 20:49:20 +0900
# LastModified: 2020-09-19 21:05:01 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
import sys

input_ = sys.stdin.readline

# 整数1個だけ
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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)