#include #include using namespace std; int main() { int N; cin >> N; vector ans; for (int i = 0; i < N; i++) { ans.push_back(2 * N - 1); } int now = 0; vector did(N, false), usd(N + 1, false); did[0] = true; usd[N] = true; int cnt = 0; for (int i = 1; i < N; i++) { int fl = 1; while (fl < N && (did[(now + fl) % N] || usd[fl])) fl++; if (fl == N) { if (cnt) { return 139; } fl = 1; while (usd[fl]) { fl++; } } //cout << fl << endl; for (int j = 0; j < fl; j++) { ans.push_back(2 * fl - 1); } did[(now + fl) % N] = true; usd[fl] = true; now = (now + fl) % N; } cout << 2 * N - 1 << endl; for (int i = 0; i < 2 * N - 1; i++) { for (int j = 0; j < N; j++) { cout << ans[i + j * (2 * N - 1)] << (j < N - 1 ? " " : ""); } cout << endl; } }