#include<cstdio>

using namespace std;

inline int In(){
	char c=getchar(); int x=0,ft=1;
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') ft=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
	return x*ft;
}

int main(){
	int K=In();
	if(K<=500){
		int n=K; printf("%d\n",n);
		for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
		printf("%d%c",i,j==n?'\n':' ');
	}
	if(K>500){
		int n=(K+3)/4*2; printf("%d\n",n);
		for(int i=1;i<=n;++i) for(int j=1;j<=n;++j){
			int val=(i+j)%n+(i&1?0:n)+1; if(val>K) val-=n;
			printf("%d%c",val,j==n?'\n':' ');
		}
	}
	return 0;
}