#include <cstdio>

int K, N;

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