#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=505,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m;
int main(){
//	freopen("1.in","r",stdin);
	m=read();n=500;
	if (m<=500){
		printf("%d\n",m);
		for (int i=1;i<=m;i++){
			for (int j=1;j<=m;j++) printf("%d ",i);
			printf("\n");
		}
		return 0;
	}
	m-=n;printf("%d\n",n);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			int t=(i+j)%n+1;
			if ((t<=m)&&(i&1)) t+=n;
			printf("%d ",t);
		}
		printf("\n");
	}
	return 0;
}