#K95547. Sorted Matrix Elements

    ID: 38887 Type: Default 1000ms 256MiB

Sorted Matrix Elements

Sorted Matrix Elements

You are given an n×nn \times n matrix in which each row and each column is sorted in ascending order. Your task is to output all the elements of the matrix in sorted order.

The input is provided from standard input (stdin) and the output should be printed to standard output (stdout).

For example, given the matrix below:
3 1 5 9 10 11 13 12 13 15
the output should be: 1 5 9 10 11 12 13 13 15.

inputFormat

The first line of the input contains a single integer nn, representing the size of the square matrix. The following nn lines each contain nn space-separated integers representing the matrix elements.

outputFormat

Print a single line containing all the elements of the matrix in sorted order, separated by spaces.## sample

3
1 5 9
10 11 13
12 13 15
1 5 9 10 11 12 13 13 15