#include <cstdio>

int k,n;
inline int val(const int &i,const int &j){
	int v=(i+n-j)%n+1+(i%2)*n;
	return v>k?v-n:v;
}
int main(){
	scanf("%d",&k);
	if(k==1){puts("1\n1");return 0;}
	n=(k+1)>>1;
	n+=(n%2);
	printf("%d\n",n);
	for(int i=1;i<=n;i++,putchar('\n'))
		for(int j=1;j<=n;j++)
			printf("%d ",val(i,j));
}