#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main() { int N; cin >> N; int mapping[2 * N][2 * N]; memset(mapping, -1, sizeof(mapping)); for (int x = 2 * N - 1; x >= 1; --x) { if (x % 2 == 0) { for (int y = 1; y <= x; ++y) { mapping[y][x] = 2 * N - y; } } else { for (int y = x; y >= 1; --y) { mapping[y][x] = x - y + 1; } } } vector counter(2 * N, 0); int ans[2 * N][N]; for (int y = 1; y <= 2 * N - 1; ++y) { for (int x = 1; x <= 2 * N - 1; ++x) { int id = mapping[y][x]; if (id == -1) continue; int idx = counter[id]; ans[id][idx] = x; counter[id]++; } } cout << 2 * N - 1 << endl; for (int id = 1; id <= 2 * N - 1; ++id) { for (int i = 0; i < N; ++i) { cout << ans[id][i]; if (i != N - 1) cout << " "; } cout << endl; } return 0; }