Dominant table
Limits: 1 sec., 512 MiB
This statement was translated automatically from Ukrainian.
Marichka wants to build a table of numbers from \(1\) to \(k\), and not just a simple table.
Zenyk has 2 arrays \(a\) and \(b\) of length \(k\). Marichka wants her table to have \(n=\sum a_i\) rows and \(m = \sum b_i\) columns. Also, in exactly \(a_x\) rows, the value \(x\) must be strictly greater than any other values. Similarly, the value \(y\) must be strictly greater than any other values in exactly \(b_y\) columns.
Help Marichka build such a table.
Input
The first line contains a single integer \(k\).
The second line contains \(k\) integers \(a_i\).
The third line contains \(k\) integers \(b_i\).
Output
In the first line, print TAK if the desired table
exists. If such a table does not exist, print NI.
If the table exists, in the next \(n\) lines print \(m\) numbers each – the values in the table. If there are multiple possible tables, print any of them.
Constraints
\(1 \le k \le 250\),
\(\mathbf{2} \le a_i, b_i \le 500\),
\(\sum a_i \le 500\),
\(\sum b_i \le 500\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 2 2 4 3 2 | TAK 1 2 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 2 2 2 1 2 2 2 1 1 2 1 2 2 |
| Input (stdin) | Output (stdout) |
|---|---|
| 3 2 2 2 2 2 2 | TAK 1 2 1 3 1 2 2 1 2 1 3 1 1 2 3 2 3 2 3 1 2 2 2 3 1 1 3 3 3 3 3 3 2 2 1 3 |
Notes
In the first example, the values of 1 are more than the values of 2 in the first and second rows, and in all other rows, there are more values of 2. Accordingly, there are 2 rows with more ones and 4 rows with more twos, which was required. Also, there are more values of 1 in the first, third, and fifth columns, while the second and fourth have more values of 2.
In the second example, the first two rows have the most values of 1, the next two rows have the most values of 2, and the last two rows have the most values of 3. Similarly for the columns.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|