Score : $1200$ points
We have $N$ irregular jigsaw pieces. Each piece is composed of three rectangular parts of width $1$ and various heights joined together. More specifically:
Snuke is arranging these pieces on a square table of side $10^{100}$. Here, the following conditions must be held:
Determine whether such an arrangement is possible.
Input is given from Standard Input in the following format:
$N$ $H$ $A_1$ $B_1$ $C_1$ $D_1$ $A_2$ $B_2$ $C_2$ $D_2$ : $A_N$ $B_N$ $C_N$ $D_N$
If it is possible to arrange the pieces under the conditions, print YES
; if it is impossible, print NO
.
3 4 1 1 0 0 2 2 0 1 3 3 1 0
YES
The figure below shows a possible arrangement.
4 2 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1
NO
10 4 1 1 0 3 2 3 2 0 1 2 3 0 2 1 0 0 3 2 0 2 1 1 3 0 3 2 0 0 1 3 2 0 1 1 1 3 2 3 0 0
YES