#include <bits/stdc++.h>

using namespace std;

int n = 500, k, a[505][505];

int main() {
	scanf("%d", &k);
	if (k <= n) {
		printf("%d\n", k);
		for (int i = 1; i <= k; ++i)
			for (int j = 1; j <= k; ++j)
				printf("%d%c", i, j == k ? '\n' : ' ');
		return 0;
	}

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			if (i + n + 1 > k)
				a[j][(i + j) % n] = i + 1;
			else
				a[j][(i + j) % n] = (j & 1) ? i + 1 + n : i + 1;
	printf("%d\n", n);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			printf("%d%c", a[i][j], j == n - 1 ? '\n' : ' ');
}