import java.util.*;

public class Clearer {
    public int[][] clearZero(int[][] mat, int n) {
        // write code here
        boolean [] flagh = new boolean [n];
        boolean [] flagl = new boolean [n];
        for (int i = 0; i < n; i++) {
            flagh[i] = false;
            flagl[i] = false;
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (mat[i][j] == 0) {
                    flagh[i] = true;
                    flagl[j] = true;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            if (flagh[i]) {
                for (int j = 0; j < n; j++) {
                    mat[i][j] = 0;
                }
            }
        }


        for (int j = 0; j < n; j++) {
            if (flagl[j]) {
                for (int i = 0; i < n; i++) {
                    mat[i][j] = 0;
                }
            }
        }

        return mat;

    }
}