#K48372. Reshape and Flatten Array
Reshape and Flatten Array
Reshape and Flatten Array
You are given two integers \(n\) and \(m\), followed by \(n \times m\) integer elements. Your task is to reshape these elements into a 2-dimensional array with \(n\) rows and \(m\) columns, and then flatten the array back into a 1-dimensional list in row-major order.
Note: The total number of elements is guaranteed to be exactly \(n \times m\). Ensure that you read input from standard input (stdin) and write output to standard output (stdout).
Example:
Input: 2 3 1 2 3 4 5 6</p>Output: 1 2 3 4 5 6
inputFormat
The first line contains two integers \(n\) and \(m\) separated by a space. The second line contains \(n \times m\) integers separated by spaces representing the elements of the array.
outputFormat
Print the flattened array as a sequence of \(n \times m\) integers separated by space.
## sample2 3
1 2 3 4 5 6
1 2 3 4 5 6