module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int n;
    int[2][] d;
}

void parseInput(T)(out Input input, T adapter)
{
	with (input)
	{
		adapter.readf!"%d\n"(n);
        int[2] pair;
        foreach (i; 0..n)
        {
		    adapter.readf!"%d %d\n"(pair[0], pair[1]);
            d ~= pair;
        }
	}
}

struct Output
{
}

auto main2(Input* input)
{
    with (input)
    {
        int zoro = 0;
        foreach (pair; d)
        {
            if (pair[0] == pair[1])
            {
                zoro++;
                if (zoro == 3)
                    return "Yes";
            }
            else
                zoro = 0;
        }

        if (zoro == 3)
            return "Yes";
        else
            return "No";
    }
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`5
1 2
6 6
4 4
3 3
3 2
`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "Yes");
	}

	unittest // example2
	{
		string example =
`5
1 1
2 2
3 4
5 5
6 6
`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "No");
	}

	unittest // example3
	{
		string example =
`6
1 1
2 2
3 3
4 4
5 5
6 6
`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "Yes");
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		parseInput(input, new StringAdapter(example));
	}
}

class StdinAdapter
{
	// readf!"%s"は使えない
	// https://issues.dlang.org/show_bug.cgi?id=19820
	uint readf(alias format, A...)(auto ref A args) { return std.stdio.readf!format(args); }
	string readln() { return std.stdio.readln().strip(); }
}

class StringAdapter
{
	import std.format;
	string _s;
	this(string input) { _s = input; }
	uint readf(alias format, A...)(auto ref A args) { return _s.formattedRead!format(args); }
	string readln()
	{
        string ret;
		auto i = _s.countUntil("\n");
		if (i == -1) { ret = _s; _s = ""; }
        else { ret = _s[0..i]; _s = _s[i+1..$]; }
		return ret;
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, new StdinAdapter());
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}
