Shuffled Matrix

We are to read and write a square matrix of integers. It is to be written with the standard layout but it is given to us differently, with disordered rows and omitting some of them.

Input

The first line of the input provides us with a nonnegative integer, the dimension nn of the matrix. Then, the second line gives a nonnegative integer mm indicating the number of row specifications provided explicitly along the next lines. Then we have mm lines: in each of them, the first number ii is always such that 1in1 \leq i \leq n and indicates that the line specifies row ii; this number is followed by nn integers that form indeed the ii-th row of the matrix. No assumption can be made about the values ii beyond what has been indicated. In case the same row index appears multiple times, only the last one is to be considered valid. Rows that are not explicitly specified are understood to consist only of zeros.

Output

The square matrix specified by the input, written row by row: the contents of row ii is given by the last line starting by ii in the input, if any, and is just zeros if no specification for that row appears in the input.

Problem information

Author: José Luis Balcázar

Generation: 2026-01-25T17:11:35.497Z

© Jutge.org, 2006–2026.
https://jutge.org