370. Matrix Restoration
0
Easy
Yash possesses a binary matrix with dimensions n x n. Due to Raj's anger, Yash's matrix was flipped vertically.
Now, Yash requires assistance in restoring his original matrix. He entrusts you with this task and departs to locate Raj and have his matrix flipped back.
To restore the original matrix, you must perform the following operations: flip each row of the matrix horizontally, then invert it. Finally, print the resulting matrix.
Horizontal row flipping involves reversing each row of the matrix. For instance, flipping [1,1,0,1] horizontally yields [0,0,1,0].
Matrix inversion entails replacing each 0 with 1 and each 1 with 0. For example, inverting [0,1,0,0] results in [1,0,1,1].
Matrix inversion entails replacing each 0 with 1 and each 1 with 0. For example, inverting [0,1,0,0] results in [1,0,1,1].
Input Format
The first line contains an integer n.
The next n lines consist of n space-separated binary digits.
The next n lines consist of n space-separated binary digits.
Output Format
n lines containing n space-separated binary digits.
Example
Input
3
1 1 0
1 0 1
0 0 0
Output
1 0 0
0 1 0
1 1 1
Constraints
n is equal to the length of the matrix.
Each row of the matrix has a length of n.
1 is less than or equal to n, and n is less than or equal to 20.
Each element in the matrix is either 0 or 1.
Loading...
View Submissions
Console