import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n", end="\n\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (1, 0), (0, -1), (-1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 18446744073709551615 # inf = 4294967295 md = 10**9+7 # md = 998244353 class UnionFind: def __init__(self, n): self.state = [-1]*n self.size_table = [1]*n self.edge = [0]*n # cntはグループ数 self.cnt = n def root(self, u): stack = [] while self.state[u] >= 0: stack.append(u) u = self.state[u] for v in stack: self.state[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: self.edge[u] += 1 if self.edge[u] > self.size_table[u]: return True return False du = -self.state[u] dv = -self.state[v] if du < dv: u, v = v, u if du == dv: self.state[u] -= 1 self.state[v] = u self.cnt -= 1 self.size_table[u] += self.size_table[v] self.edge[u] += self.edge[v]+1 if self.edge[u] > self.size_table[u]: return True return False # グループの要素数 def size(self, u): return self.size_table[self.root(u)] m = 100 n = II() uf = UnionFind(m*m) for _ in range(n): r, c, i, j = LI1() if uf.merge(r*m+c, i*m+j): print("NO") exit() print("YES")