using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(string[] args) { int previousX = int.MaxValue; int previousY = int.MaxValue; bool valid = true; int n = Convert.ToInt32(Console.ReadLine()); for (int a0 = 0; a0 < n; a0++) { string[] tokensX = Console.ReadLine().Split(' '); int x = Convert.ToInt32(tokensX[0]); int y = Convert.ToInt32(tokensX[1]); valid = valid && IsLineOnVarticleOrHorizontal(x, y, ref previousX, ref previousY); } Console.WriteLine("{0}", valid ? "YES" : "NO"); Console.ReadLine(); } static bool IsLineOnVarticleOrHorizontal(int x, int y, ref int previousX, ref int previousY) { if (( previousX == int.MaxValue) && (previousY == int.MaxValue)) { previousX = x; previousY = y; return true; } if ((x == previousX) | (y == previousY)) { previousX = x; previousY = y; return true; } return false; } }