#C6097. Reshape and Transpose Matrix

    ID: 49819 Type: Default 1000ms 256MiB

Reshape and Transpose Matrix

Reshape and Transpose Matrix

You are given a list of integers and two positive integers \(r\) and \(c\) representing the number of rows and columns respectively. Your task is to reshape the list into a \(r \times c\) matrix if possible. If the list cannot be reshaped into such a matrix (i.e. the total number of integers is not equal to \(r\times c\)), print Invalid. Otherwise, print the matrix and its transpose in the format shown in the examples. The matrix and its transpose should be printed in a style similar to NumPy's array printing.

Note: When printing the matrix, the first row should start with "[[" and the last row should end with "]]". Each row is printed in a new line with a preceding space (except the first row) as shown in the examples.

inputFormat

The input is given via stdin and consists of two lines:

  • The first line contains two integers \(r\) and \(c\) separated by spaces.
  • The second line contains a list of integers separated by spaces.

If the number of integers provided does not equal \(r \times c\), the program should output Invalid.

outputFormat

If the list can be reshaped into a \(r \times c\) matrix, first print the matrix and then its transpose. Each matrix should be printed in a format similar to NumPy's array printing. For example, a 2x3 matrix should be printed as:

[[1 2 3]
 [4 5 6]]

And its transpose (a 3x2 matrix) as:

[[1 4]
 [2 5]
 [3 6]]

If reshaping is not possible, output Invalid.

## sample
2 3
1 2 3 4 5 6
[[1 2 3]

[4 5 6]] [[1 4] [2 5] [3 6]]

</p>