constint maxN = 50; int arr[maxN][maxN]; int arr2[maxN][maxN];
voidsolve(int n, int m){ for (int i = 0; i < n; i++) { vector<int> ve; for (int j = 0; j < m; j++) { if (!ve.empty()) { int x = ve.back(); if (arr[i][x] != arr[i][j]) { if (ve.size() > 2) { for (int k = ve.front(); k <= ve.back(); k++) arr2[i][k] = (-1) * abs(arr2[i][k]); } ve.clear(); } } ve.push_back(j); if (j == m - 1 && ve.size() > 2) { for (int k = ve.front(); k <= ve.back(); k++) arr2[i][k] = (-1) * abs(arr2[i][k]); ve.clear(); } } }
for (int j = 0; j < m; j++) { vector<int> ve; for (int i = 0; i < n; i++) { if (!ve.empty()) { int x = ve.back(); if (arr[x][j] != arr[i][j]) { if (ve.size() > 2) { for (int k = ve.front(); k <= ve.back(); k++) arr2[k][j] = (-1) * abs(arr2[k][j]); } ve.clear(); } } ve.push_back(i); if (i == n - 1 && ve.size() > 2) { for (int k = ve.front(); k <= ve.back(); k++) arr2[k][j] = (-1) * abs(arr2[k][j]); ve.clear(); } } }
for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (arr2[i][j] < 0) cout << 0 << " "; else cout << arr2[i][j] << " "; } cout << endl; } }
intmain(){ int n, m; while (!(cin >> n >> m).eof()) { for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> arr[i][j]; arr2[i][j] = arr[i][j]; } solve(n, m); }