unittest
{
	assert( [ "5", "1 2", "6 6", "4 4", "3 3", "3 2" ].solve == "Yes" );
	assert( [ "5", "1 1", "2 2", "3 4", "5 5", "6 6" ].solve == "No" );
	assert( [ "6", "1 1", "2 2", "3 3", "4 4", "5 5", "6 6" ].solve == "Yes" );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto dss = new long[ 2 ][ n ];
	foreach( ref ds; dss )
	{
		input.popFront;
		ds = input.front.split.to!( long[] );
	}
	
	auto ans = "No";
	auto c = 0L;
	foreach( ds; dss )
	{
		if( ds[ 0 ] == ds[ 1 ] )
		{
			c++;
			if( 3 <= c ) ans = "Yes";
		}
		else
		{
			c = 0;
		}
	}
	return ans;
}
