text: ans[pxp[y][z]][y][z]) ++pxp[y][z]; while (pxn[y][z] >= 0 && !ans[pxn[y][z]][y][z]) --pxn[y][z]; if (pxp[y][z] >= n || pxn[y][z] < 0) gg(); q.emplace(pxp[y][z], y, z); q.emplace(pxn[y][z], y, z); }; function<void(int, int)> exy = [&](int x, int z) { while (pyp[x][z] < m && !ans[x][pyp[x][z]][z]) ++pyp[x][z]; while (pyn[x][z] >= 0 && !ans[x][pyn[x][z]][z]) --pyn[x][z]; if (pyp[x][z] >= m || pyn[x][z] < 0) gg(); q.emplace(x, pyp[x][z], z); q.emplace(x, pyn[x][z], z); }; function<void(int, int)> exz = [&](int x, int y) { while (pzp[x][y] < k && !ans[x][y][pzp[x][y]]) ++pzp[x][y]; while (pzn[x][y] >= 0 && !ans[x][y][pzn[x][y]]) --pzn[x][y]; if (pzp[x][y] >= k || pzn[x][y] < 0) gg(); q.emplace(x, y, pzp[x][y]); q.emplace(x, y, pzn[x][y]); }; for (int y = 0; y < m; ++y) for (int z = 0; z < k; ++z) { if (bool(xp[y][z]) != bool(xn[y][z])) gg(); if (!xp[y][z]) continue; exx(y, z); } for (int x = 0; x < n; ++x) for (int z = 0; z < k; ++z) { if (bool(yp[x][z]) != bool(yn[x][z])) gg(); if (!yp[x][z]) continue; exy(x, z); } for (int x = 0; x < n; ++x) for (int y = 0; y < m; ++y) { if (bool(zp[x][y]) != bool(zn[x][y])) gg(); if (!zp[x][y]) continue; exz(x, y); } while (!q.empty()) { int x, y, z; tie(x, y, z) = q.front(); q.pop(); if (ans[x][y][z] == 0) continue; vector<int> col; if (pxp[y][z] == x) col.push_back(xp[y][z]); if (pxn[y][z] == x) col.push_back(xn[y][z]); if (pyp[x][z] == y) col.push_back(yp[x][z]); if (pyn[x][z] == y) col.push_back(yn[x][z]); if (pzp[x][y] == z) col.push_back(zp[x][y]); if (pzn[x][y] == z) col.push_back(zn[x][y]); if (col.size() == 0) continue; col.erase(unique(col.begin(), col.end()), col.end()); if (col.size() == 1) { ans[x][y][z] = col.back(); continue; } ans[x][y][z] = 0; exx(y, z); exy(x, z); exz(x, y); } for (int x = 0; x < n; ++x) { for (int y = 0; y < m; ++y) { for (int z = 0; z < k; ++z) if (ans[x][y][z] == -1) ans[x][y][z] = 0; cout << ans[x][y] << '\n'; } cout << '\n'; } return 0; }