n = int(input()) node2con = dict() con_data = 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 con0 = node2con[r0, c0] if is_0 else None con1 = node2con[r1, c1] if is_1 else None if is_0 and is_1: if con0 == con1: if con_data[con0]['roop']: clear = False else: con_data[con0]['roop'] = True else: for node in con_data[con1]['node']: node2con[node] = con0 elif is_0 and not is_1: node2con[r1, c1] = con0 con_data[con0]['node'].append((r0, c0)) elif is_1 and not is_0: node2con[r0, c0] = con1 con_data[con1]['node'].append((r1, c1)) else: node2con[r0, c0] = node2con[r1, c1] = con_num con_data[con_num] = {'node': [(r0, c0), (r1, c1)], 'roop': False} con_num += 1 print(['NO', 'YES'][clear])