#include #include using namespace std; using namespace atcoder; using ll = long long; using pl = std::pair; using mint = atcoder::modint1000000007; //using mint = atcoder::modint998244353; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) #define all(v) (v).begin(), (v).end() #define dump(var) do{ if(debug::enable) { std::cerr << #var << " : "; debug::print(var); } } while(0); constexpr int di[4] = {1, -1, 0, 0}; constexpr int dj[4] = {0, 0, 1, -1}; constexpr long long inf = 1LL<<60; template inline void chmax(T &a, T b) { a = std::max(a, b); }; template inline void chmin(T &a, T b) { a = std::min(a, b); }; template void vprint(const std::vector& v) { for(int i = 0; i < v.size(); i++) { std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); } } template void vprintln(const std::vector& v) { for(int i = 0; i < v.size(); i++) { std::cout << v[i] << "\n"; } } template void vprint(const std::vector>& v) { for(int i = 0; i < v.size(); i++) { std::cout << v[i].val() << (i == v.size()-1 ? "\n" : " "); } } template void vprintln(const std::vector>& v) { for(int i = 0; i < v.size(); i++) { std::cout << v[i].val() << "\n"; } } namespace debug { #if defined(ONLINE_JUDGE) const bool enable = false; #else const bool enable = true; #endif template void push(const T& e) { std::cerr << e; } template void push(const atcoder::static_modint& e) { std::cerr << e.val(); } template void push(const std::pair& e) { std::cerr << "("; push(e.first); std::cerr << ","; push(e.second); std::cerr << ")"; } template void push(const std::tuple& e) { std::cerr << "("; push(get<0>(e)); std::cerr << ","; push(get<1>(e)); std::cerr << ","; push(get<2>(e)); std::cerr << ")"; } template void print(const T& e) { push(e); std::cerr << "\n"; } template void print(const std::vector& v) { for(int i = 0; i < v.size(); i++) { push(v[i]); std::cerr << " "; } std::cerr << "\n"; } template void print(const std::vector>& v) { std::cerr << "\n"; for(int i = 0; i < v.size(); i++) { std::cerr << i << ": "; print(v[i]); } } }; void solve() { ll n; cin >> n; vector ans(2*n-1, vector(n, -1)); ll prev = -1; for(ll val = 2*n-1; 2*val > 2*n-1; val--) { ll j = 2*n-1 - val; ll rem = 2*n - 1 - val; ll srt; if(rem <= 1) { srt = 0; } else if(rem == 2) { srt = 1; } else if(rem == 3) { srt = 3; } else if(rem >= 4) { srt = 5 + (2 * (rem - 4)); } rep(x, 0, rem) { ll i = (x + srt) % (2*n-1); ans[i][j] = rem; } rep(i, 0, 2*n-1) if(ans[i][j] == -1) ans[i][j] = val; } cout << 2 * n - 1 << endl; for(auto v : ans) vprint(v); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }