#include <cstddef>
class Clearer {
  public:
    vector<vector<int> > clearZero(vector<vector<int> > mat, int n) {

        // write code here
        if (n <= 1)
            return mat;
        std::set<int> rows, cols;
        for (size_t i = 0; i < n; i++) {
            for (size_t j = 0; j < n; j++) {
                if (mat[i][j] == 0) {
                    rows.insert(i);
                    cols.insert(j);
                }
            }
        }

        for (auto r : rows) {
            for (size_t j = 0; j < n; j++) {
                mat[r][j] = 0;
            }
        }
        for (auto c : cols) {
            for (size_t j = 0; j < n; j++) {
                mat[j][c] = 0;
            }
        }

        return mat;
    }
};