#C6439. Matrix Transposition and Validation

    ID: 50199 Type: Default 1000ms 256MiB

Matrix Transposition and Validation

Matrix Transposition and Validation

In this problem, you are given a matrix of integers provided as input in a row-based format. Your task is to check if the matrix is valid, i.e. every row contains the same number of integers. If the matrix is valid, output its transpose; otherwise, output the string "False".

The transpose of a matrix (A) is a new matrix (A^T) whose rows are the columns of (A). For example, if (A = [[1, 2], [3, 4]]), then (A^T = [[1, 3], [2, 4]]).

inputFormat

The input is read from standard input (stdin) as follows:

  1. The first line contains an integer (R), the number of rows in the matrix.
  2. The following (R) lines each contain space-separated integers representing a row of the matrix.

Note: The matrix is considered valid only if each row has the same number of integers.

outputFormat

If the input matrix is valid, output its transpose in the following format:

  1. The first line should contain an integer representing the number of rows in the transposed matrix (which is equal to the number of columns of the original matrix).
  2. Each of the following lines should contain the space-separated integers of one row of the transposed matrix.

If the matrix is invalid (i.e. if not all rows have the same number of integers), output the string "False" (without quotes) to standard output.## sample

2
1 2
3 4
2

1 3 2 4

</p>