Shuffled Matrix X90788


Statement
 

pdf   zip

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.

Public test cases
  • Input

    3
    2
    3 1 2 3
    1 3 4 5

    Output

    3 4 5 
    0 0 0 
    1 2 3 
    
  • Input

    2
    0

    Output

    0 0 
    0 0 
    
  • Input

    4
    2
    4 1001 1002 1003 1004
    2 2011 2012 2013 2014

    Output

    0 0 0 0 
    2011 2012 2013 2014 
    0 0 0 0 
    1001 1002 1003 1004 
    
  • Input

    2
    3
    1 5 6
    2 3 4
    2 7 8

    Output

    5 6 
    7 8 
    
  • Input

    1
    5
    1 7
    1 6
    1 5
    1 4
    1 3

    Output

    3 
    
  • Information
    Author
    José Luis Balcázar
    Language
    English
    Official solutions
    Python
    User solutions
    Python