584. Set Matrix Zeroes

0

Medium

Given an integer matrix with m rows and n columns, if any element in the matrix is equal to 0, replace all the elements in its corresponding row and column with 0's. This operation must be performed in-place, without using any additional matrix, and the space complexity must be O(1).

Input Format

The first line contains the number of rows in the matrix.
The second line contains the number of columns in the matrix.
The following lines contain the elements of the matrix.

Output Format

Print the modified matrix.

Example

Input

3
3
1 1 1
1 0 1
1 1 1

Output

1 0 1
0 0 0
1 0 1

Constraints

m == matrix.length

n == matrix[0].length

1 <= m, n <= 200

-2

n == matrix[0].length

1 <= m, n <= 200

-2

^{31}<= matrix[i][j] <= 2^{31}- 1Loading...

View Submissions

Console