n = int(input()) node2con = dict() con_num = 0 clear = True for _ in range(n): r0, c0, r1, c1 = map(int, input().split()) if not clear: continue is_0 = (r0, c0) in node2con is_1 = (r1, c1) in node2con if is_0 and is_1: clear = False elif is_0 and not is_1: node2con[r1, c1] = node2con[r0, c0] elif is_1 and not is_0: node2con[r0, c0] = node2con[r1, c1] else: node2con[r0, c0] = node2con[r1, c1] = con_num con_num += 1 print(['NO', 'YES'][clear])