Score : $500$ points
Print the number of sequences $a$ that are permutations of $(1, 2, 3, \dots, N)$ and satisfy the following condition:
Input is given from Standard Input in the following format:
$N$ $M$ $X_1$ $Y_1$ $Z_1$ $X_2$ $Y_2$ $Z_2$ $X_3$ $Y_3$ $Z_3$ $\hspace{23pt} \vdots$ $X_M$ $Y_M$ $Z_M$
Print the answer.
3 1 2 2 1
4
The four sequences $a$ satisfying the condition are:
$(1, 2, 3)$ and $(2, 1, 3)$ violate the condition, since each of them has two numbers less than or equal to $2$ among $a_1, a_2$.
5 2 3 3 2 4 4 3
90
18 0
6402373705728000