#include using namespace std; int main(){ int N; cin >> N; vector> ans(N * 2 - 1); priority_queue, vector>, greater>> pq; for (int i = 1; i <= N * 2 - 1; i++){ int R = i; if (i % 2 == 1){ ans[N * 2 - 2].push_back(i); R--; } if (i >= 2 && i <= N){ R -= 2; } vector> P; for (int j = 0; j < R; j++){ int p = pq.top().second; pq.pop(); ans[p].push_back(i); P.push_back(make_pair(ans[p].size(), p)); } for (auto P2 : P){ pq.push(P2); } if (i >= 2 && i <= N){ ans[i * 2 - 4].push_back(i); ans[i * 2 - 3].push_back(i); pq.push(make_pair(1, i * 2 - 4)); pq.push(make_pair(1, i * 2 - 3)); } } cout << N * 2 - 1 << endl; for (int i = 0; i < N * 2 - 1; i++){ for (int j = 0; j < N; j++){ cout << ans[i][j]; if (j < N - 1){ cout << ' '; } } cout << endl; } }