405820: GYM102129 B Associativity Degree

Memory Limit:0 MB Time Limit:6 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Associativity Degreetime limit per test6 secondsmemory limit per test512 mebibytesinputstandard inputoutputstandard output

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$$$.

Input

The 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.

Output

For 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$$$.

ExamplesInput
3 1
27
Output
YES
1 1 1
1 2 3
1 3 2
Input
1 2
0
1
Output
NO
YES
1
Note

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.

加入题单

上一题 下一题 算法标签: