#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int m[555][555];
int main()
{
	int num;
	scanf("%d", &num);
	if (num == 1)
	{
		printf("1\n1\n");
		return 0;
	}
	int x = (num + 3) / 4 * 2;
	printf("%d\n", x);
	for (int i = 0; i < x; i++)for (int j = 0; j < x; j++)m[j][(i + j) % x] = i + x*(j % 2) + 1;
	for (int i = 0; i < x; i++)for (int j = 0; j < x; j++)if (m[i][j]>num)m[i][j] = m[(i + 1) % x][(j + 1) % x];
	for (int i = 0; i < x; i++)
	{
		for (int j = 0; j < x; j++)
		{
			printf("%d ", m[i][j]);
		}
		printf("\n");
	}
}
