#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int n, m;

int main() {
#ifdef isLOCAL
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif 

    cin >> m, n = (m - 1 >> 2) + 1 << 1;
    if (m <= 500) {
        cout << m << endl;
        for (int i = 1; i <= m; ++i)
            for (int j = 1; j <= m; ++j)
                printf("%d%c", (i + j - 2) % m + 1, " \n"[j == m]);
        return 0;
    }
    cout << n << endl;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            int tmp = (i + j - 2) % n + 1;
            if (i % 2 == 0 && tmp + n <= m) tmp += n;
            printf("%d%c", tmp, " \n"[j == n]);
        }
    return 0;
}
