#include using namespace std; vector> buildCells(int h, int w) { vector> cells; cells.reserve(h * w); for (int row = 0; row < h; row++) { if (row % 2 == 0) { for (int col = 0; col < w; col++) { cells.push_back({row, col}); } } else { for (int col = w - 1; col >= 0; col--) { cells.push_back({row, col}); } } } return cells; } bool possible(int h, int w, int m) { int total = h * w; int middleCount = total - 2 * m; if (m == 0) { return false; } return !(h > 1 && w > 1 && h % 2 == 1 && w % 2 == 1 && middleCount == 1); } vector> buildSparse(int h, int w, int m, const vector>& cells) { int total = h * w; int k = m - 1; int low = 1; int high = total; int middle = k + 1; vector> grid(h, vector(w)); for (int t = 1; t <= total; t++) { auto [row, col] = cells[t - 1]; if (t <= 2 * k) { if (t % 2 == 1) { grid[row][col] = low++; } else { grid[row][col] = high--; } } else { grid[row][col] = middle++; } } return grid; } vector> buildDense(int h, int w, int m, int middleCount, const vector>& cells) { int total = h * w; vector> grid(h, vector(w, 0)); vector values; values.reserve(middleCount); for (int value = m + 1; value <= m + middleCount; value++) { values.push_back(value); } swap(values[middleCount - 2], values[middleCount - 1]); for (int t = 0; t < middleCount; t++) { auto [row, col] = cells[t]; grid[row][col] = values[t]; } int low = 1; int high = total; for (int row = 0; row < h; row++) { for (int col = 0; col < w; col++) { if (grid[row][col] != 0) { continue; } if ((row + col) % 2 == 0) { grid[row][col] = high--; } else { grid[row][col] = low++; } } } return grid; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int h; int w; int m; cin >> h >> w >> m; int total = h * w; int middleCount = total - 2 * m; if (!possible(h, w, m)) { cout << -1 << '\n'; return 0; } vector> cells = buildCells(h, w); bool dense = (h > 1 && w > 1 && h % 2 == 1 && w % 2 == 1 && middleCount <= 2 * w - 3); vector> grid = dense ? buildDense(h, w, m, middleCount, cells) : buildSparse(h, w, m, cells); for (int row = 0; row < h; row++) { for (int col = 0; col < w; col++) { if (col > 0) { cout << ' '; } cout << grid[row][col]; } cout << '\n'; } return 0; }