int c1, c2, c3, ug; in >> c1 >> c2 >> c3 >> ug; if (ug % 2 == 0) { } vector> res(5, vector(800, 0)); int firstRow = 1; int lastRow = 3; int lastCol; int num = 2; if (ug % 2 == 1) { res[1][0] = 1; res[1][1] = 1; res[2][0] = 1; res[3][0] = 2; res[3][1] = 2; int topCnt = 2; int botCnt = 2; --ug; --c2; --c3; for (int i = 0; i < ug / 2; ++i) { ++num; if (topCnt < botCnt) { res[1][topCnt] = num; res[0][topCnt] = num; ++topCnt; res[0][topCnt] = num; ++topCnt; ++num; res[1][topCnt] = num; res[0][topCnt] = num; ++topCnt; res[1][topCnt] = num; ++topCnt; firstRow = 0; } else { res[3][botCnt] = num; res[4][botCnt] = num; ++botCnt; res[4][botCnt] = num; ++botCnt; ++num; res[3][botCnt] = num; res[4][botCnt] = num; ++botCnt; res[3][botCnt] = num; ++botCnt; lastRow = 4; } } for (int i = 0; i < c3; ++i) { ++num; if (topCnt < botCnt) { for(int j: range(3)) { res[1][topCnt] = num; ++topCnt; } } else { for(int j: range(3)) { res[3][botCnt] = num; ++botCnt; } } } for (int i = 0; i < c2; ++i) { ++num; if (topCnt < botCnt) { for(int j: range(2)) { res[1][topCnt] = num; ++topCnt; } } else { for(int j: range(2)) { res[3][botCnt] = num; ++botCnt; } } } for (int i = 0; i < c1; ++i) { ++num; if (topCnt < botCnt) { for(int j: range(1)) { res[1][topCnt] = num; ++topCnt; } } else { for(int j: range(1)) { res[3][botCnt] = num; ++botCnt; } } } cerr << topCnt << ' ' << botCnt << endl; assert(topCnt == botCnt); ++num; res[1][topCnt] = num; res[2][topCnt] = num; res[3][topCnt] = num; lastCol = topCnt; } else { res[1][0] = 1; res[1][1] = 1; res[2][0] = 1; res[3][0] = 2; res[3][1] = 2; res[3][2] = 2; int topCnt = 2; int botCnt = 3; --ug; --ug; --c3; --c3; for (int i = 0; i < ug / 2; ++i) { ++num; if (topCnt < botCnt) { res[1][topCnt] = num; res[0][topCnt] = num; ++topCnt; res[0][topCnt] = num; ++topCnt; ++num; res[1][topCnt] = num; res[0][topCnt] = num; ++topCnt; res[1][topCnt] = num; ++topCnt; firstRow = 0; } else { res[3][botCnt] = num; res[4][botCnt] = num; ++botCnt; res[4][botCnt] = num; ++botCnt; ++num; res[3][botCnt] = num; res[4][botCnt] = num; ++botCnt; res[3][botCnt] = num; ++botCnt; lastRow = 4; } } for (int i = 0; i < c3; ++i) { ++num; if (topCnt < botCnt) { for(int j: range(3)) { res[1][topCnt] = num; ++topCnt; } } else { for(int j: range(3)) { res[3][botCnt] = num; ++botCnt; } } } for (int i = 0; i < c2; ++i) { ++num; if (topCnt < botCnt) { for(int j: range(2)) { res[1][topCnt] = num; ++topCnt; } } else { for(int j: range(2)) { res[3][botCnt] = num; ++botCnt; } } } for (int i = 0; i < c1; ++i) { ++num; if (topCnt < botCnt) { for(int j: range(1)) { res[1][topCnt] = num; ++topCnt; } } else { for(int j: range(1)) { res[3][botCnt] = num; ++botCnt; } } } cerr << topCnt << ' ' << botCnt << endl; assert(topCnt + 1 == botCnt); ++num; for(int j: range(3)) { res[1][topCnt] = num; ++topCnt; } ++num; res[3][botCnt] = num; res[3][botCnt + 1] = num; res[2][botCnt + 1] = num; lastCol = botCnt + 1; } out << (lastRow - firstRow + 1) << ' ' << lastCol + 1 << "\n"; for (int i: inclusiveRange(firstRow, lastRow)) { for (int j: inclusiveRange(0, lastCol)) { out << res[i][j] << " "; } out << "\n"; }