Three-dimensional rooks
The game of three-dimensional chess is played on a cubic board of size N×N×N. A three-dimensional rook can move any number of squares in a straight line along any of the six possible directions (one direction in each of the three dimensions).
On this board, K rooks are placed. Your task is to write a program that determines whether these rooks cover the entire board.
Input
The first line of the input contains a natural number N (1 ≤ N ≤ 1000), representing the dimensions of the game cube, and the number of rooks K (0 ≤ K ≤ 10^6). The next K lines each contain a triplet of numbers, specifying the coordinates of each rook (each coordinate is a natural number from 1 to N).
Output
Print YES if the rooks cover the entire cube. If they do not, print NO on the first line, followed by the coordinates of any cell that is not covered by any rook on the second line.