class Clearer {
public:
vector<vector<int> > clearZero(vector<vector<int> > mat, int n) {
bool fr = any_of(mat[0].begin(), mat[0].end(), [](auto x) {return x==0;});
bool fc = false;
for (int i = 0; i < n; ++i) {
if (mat[i][0] == 0) {
fc = true;
break;
}
}
for (int i = 1; i < n; ++i) {
for (int j = 1; j < n; ++j) {
if (mat[i][j] == 0) mat[i][0] = mat[0][j] = 0;
}
}
for (int i = 1; i < n; ++i) {
for (int j = 1; j < n; ++j) {
if (mat[i][0] == 0 || mat[0][j] == 0) mat[i][j] = 0;
}
}
if (fr) fill(mat[0].begin(), mat[0].end(), 0);
if (fc) for (int i = 0; i < n; ++i) mat[i][0] = 0;
return mat;
}
};