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 C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;

using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        /////////////////////////////////////////

        //回答
        //Console.WriteLine(Math.Ceiling((double)N / X) * T);
        //Console.WriteLine("");

        //整数の入力
        //int input = int.Parse(Console.ReadLine());

        //文字列の入力
        //string input = Console.ReadLine();

        /////////////////////////////////////////


        ////A
        //string input =Console.ReadLine();

        //if(input.EndsWith("s"))
        //{
        //    Console.WriteLine(input.Substring(0, input.Length) + "es");
        //}
        //else
        //{
        //    Console.WriteLine(input + "s");
        //}

        //B
        int N = int.Parse(Console.ReadLine());

        int count = 0;
        for (int i = 0; i <N; i++)
        {
            string[] inputs = Console.ReadLine().Split(' ');
            int[] D = inputs.Select(int.Parse).ToArray();

            if(D[0] == D[1])
            {
                count++;
                if(count == 3)
                {
                    Console.WriteLine("Yes");
                    break;
                }
                      
            }
            else
            {
                count = 0;
            }
        }
        if(count != 3)
        {
            Console.WriteLine("No");
        }


        /* 階乗 */
        //long fact = 1;

        ///* 自然数の入力 */
        //int num = int.Parse(Console.ReadLine()) ;


        //double tmp = ((double)num - 1) * num / 2;

        //Console.WriteLine("tmp : " + tmp);
        //Console.WriteLine("Math.Pow(8, num - 2) : " + Math.Pow(8, num - 2));
        //Console.WriteLine("res : " + ((double)tmp * Math.Pow(8, num - 2) * 2) % 1000000007);



        ////複数の入力
        //string[] line = Console.ReadLine().Split(' ');
        //int a = int.Parse(line[0]);
        //int b = int.Parse(line[1]);
        //int c = int.Parse(line[2]);
        //int d = int.Parse(line[3]);

        //if ((double)D/S <= T)
        //{
        //    Console.WriteLine("Yes");
        //}
        //else
        //{
        //    Console.WriteLine("No");
        //}



        ////文字列の入力
        //string S = Console.ReadLine();
        //string T = Console.ReadLine();

        //int ans = T.Length;
        //for (int i = 0; i < S.Length - T.Length + 1; i++)
        //{
        //    int count = 0;
        //    for (int j = 0; j < T.Length; j++)
        //    {
        //        if (S[i + j] != T[j])
        //        {
        //            count++;
        //            if (count >= ans)
        //            {
        //                break;
        //            }
        //        }
        //    }
        //    if (count < ans)
        //    {
        //        ans = count;
        //    }

        //    //Console.WriteLine(S.Substring(i, T.Length));
        //    //Console.WriteLine(count);
        //}
        //Console.WriteLine(ans);

        //////複数の入力
        //int N = int.Parse(Console.ReadLine());
        //string[] strArray = Console.ReadLine().Split(' ');
        //long[] A = strArray.Select(long.Parse).ToArray();
        //long[] sumArray = new long[A.Length];

        //long modNum = 1000000007;
        //long ans = 0;

        //long tmp = 0;
        //for(int j = N - 1; j >= 0; j--)
        //{
        //    tmp = (tmp + A[j]) % modNum;
        //    sumArray[j] = tmp;
        //}

        ////for (int i = 0; i < N; i++)
        ////{
        ////    Console.Write(sumArray[i] + " ");
        ////}
        ////Console.WriteLine();

        //for (int i = N - 1; i > 0; i--)
        //{
        //    long hoge = (A[i - 1] * sumArray[i]) % modNum;

        //    // Console.WriteLine(i + " : " + A[i - 1] + " * " + sumArray[i]);
        //    // Console.WriteLine("add : " + hoge);

        //    ans += hoge;

        //}

        //Console.WriteLine(ans % modNum);




        //    int j = i
        //    for (int j = i; j > i; j++)
        //    {
        //        long aiaj = (long)intArray[i] * intArray[j];
        //        ans += aiaj;
        //        //if(aiaj < modnum)
        //        //{
        //        //    ans += aiaj;
        //        //}
        //        //else
        //        //{
        //        //    ans += aiaj % modnum;
        //        //}
        //    }
        //}

        //Console.WriteLine(ans % modnum);



        //string[] line = Console.ReadLine().Split(' ');
        //int H = int.Parse(line[0]);
        //int W = int.Parse(line[1]);

        //line = Console.ReadLine().Split(' ');
        //int Ch = int.Parse(line[0]);
        //int Cw = int.Parse(line[1]);

        //line = Console.ReadLine().Split(' ');
        //int Dh = int.Parse(line[0]);
        //int Dw = int.Parse(line[1]);

        //string[] S = new string[H];

        //for(int i = 0; i < H; i++)
        //{
        //    // line = Console.ReadLine().Split('');
        //    string line2 = Console.ReadLine();
        //    //Console.WriteLine(line2);
        //    S[i] = line2;

        //    //for(int j = 0; j < W; j++)
        //    //{
        //    //    Console.WriteLine(line2[j]);
        //    //    //Console.WriteLine(S[i][j]);
        //    //}
        //}

        //for (int i = 0; i < H; i++)
        //{
        //    for (int j = 0; j < W; j++)
        //    {
        //    }
        //}


        ///////////////////////////////////////////////
        //long N = int.Parse(Console.ReadLine());
        //string[] A = Console.ReadLine().Split(' ');

        //long h = long.Parse(A[0]);
        //long dai_sum = 0;
        //for(long i = 1; i < N; i++)
        //{
        //    long ai = long.Parse(A[i]);
        //    //Console.WriteLine("-- " + i + "--");
        //    //Console.WriteLine("dai_sum : " + dai_sum);
        //    //Console.WriteLine("h : " + h);
        //    //Console.WriteLine("a[i] : " + ai);
        //    if (ai < h)
        //    {
        //        long dai = h - ai;
        //        dai_sum += dai;
        //        //Console.WriteLine("add dai : " + dai);
        //    }
        //    else
        //    {
        //        h = ai;
        //    }
        //}

        //Console.WriteLine(dai_sum);







        //==============
        //String N = Console.ReadLine();

        //int sum = 0;
        //for(int i =0;i< N.Length; i++)
        //{
        //    //Console.WriteLine("sum : " + sum);
        //    //Console.WriteLine("N[i] : " + (N[i] - '0'));
        //    sum += N[i] - '0';

        //}

        ////Console.WriteLine("sum : " + sum);

        //if (sum % 9 == 0)
        //{
        //    Console.WriteLine("Yes");
        //}
        //else
        //{
        //    Console.WriteLine("No");
        //}
        //=============



        //スペース区切りの整数の入力
        //string[] dates = Console.ReadLine().Split(' ');
        //string[] amounts = Console.ReadLine().Split(' ');

        //double date = double.Parse(input[0]);
        //double amount = double.Parse(input[1]);

        //double date = double.Parse(input[0]);
        //double amount = double.Parse(input[1]);

        //var L2 = L.Distinct().OrderBy(o => o);
        //var L2 = L.OrderBy(o => o).ToArray();

        //string input = Console.ReadLine();
        //int b = int.Parse(input[0]);
        //int c = int.Parse(input[1]);
        //文字列の入力
        //string s = Console.ReadLine();
        //出力


        //////////////////a
        //整数の入力
        //int N = int.Parse(Console.ReadLine());
        //if (N == 0)
        //{
        //    Console.WriteLine("1");
        //}
        //else
        //{
        //    Console.WriteLine("0");
        //}
        //////////////////b

        //////複数の入力
        //string[] line = Console.ReadLine().Split(' ');
        //int a = int.Parse(line[0]);
        //int b = int.Parse(line[1]);
        //int c = int.Parse(line[2]);
        //int d = int.Parse(line[3]);

        //long result = Math.Max(Math.Max((long)a * c, (long)a * d), Math.Max((long)b * c, (long)b * d));
        //Console.WriteLine(result);

        //////////////////b

    }
}