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 in Scala (2.13.1) (judge verdict: Accepted)

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val d = Array.fill(n, 2)(sc.nextInt)

  val three = countZ(0, 0, d.map(z => z(0) == z(1)))
  if(three >= 3) {
    println("Yes")
  } else {
    println("No")
  }

  def countZ(z: Int, max: Int, dd: Array[Boolean]): Int ={
    val nz = if (dd.head) z + 1 else 0
    val nmax = Math.max(max, nz)
    return if(dd.length == 1) {
      nmax
    } else {
      countZ(nz, nmax, dd.tail)
    }
  }

}