405820: GYM102129 B Associativity Degree
Description
Consider a binary operation $$$\circ$$$ defined on numbers $$$1$$$ through $$$n$$$: $$$$$$\circ : \{1,\dots,n\} \times \{1,\dots,n\} \to \{1,\dots,n\}\text{.}$$$$$$
Let us define its associativity degree as the number of triplets $$$i,j,k \in \{1,\dots,n\}$$$ for which $$$\circ$$$ is associative: $$$$$$i \circ (j \circ k) = (i \circ j) \circ k\text{.}$$$$$$
Your task is, given $$$n$$$ and $$$k$$$, to construct an operation $$$\circ$$$ such that its associativity degree is exactly $$$k$$$.
InputThe first line of input contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n \leq 64$$$, $$$1 \leq q \cdot n^2 \leq 10^6$$$).
The $$$i$$$-th of the next $$$q$$$ lines contains a single integer $$$k_i$$$ ($$$0 \leq k_i \leq n^3$$$).
It is guaranteed that all $$$k_i$$$ are distinct.
OutputFor each given value of $$$k_i$$$, do the following:
If there is no operation $$$\circ$$$ with associativity degree $$$k_i$$$ for given $$$n$$$, output "NO" on a single line.
Otherwise, output "YES" on the first line, followed by $$$n$$$ lines containing $$$n$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line must be equal to $$$i \circ j$$$.
ExamplesInput3 1 27Output
YES 1 1 1 1 2 3 1 3 2Input
1 2 0 1Output
NO YES 1Note
The operation from the first sample can be concisely described as $$$i \circ j = 1 + (\left(i - 1) \cdot (j - 1)\right) \bmod 3$$$, and it is fully associative.