#include <bits/stdc++.h>

using namespace std;

int N, K;

int main() {
    scanf("%d", &K);
    if (K == 1) {
        printf("1\n1\n");
        return 0;
    }
    N = (K + 3) / 4 * 2;
    printf("%d\n", N);
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            int a = (i + j) % N + 1;
            if (i & 1) a += N;
            if (a > K) a -= N;
            printf("%d ", a);
        }
        printf("\n");
    }
}
