#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

#define N 1010
ll a[N][N];
int main(){
    ll k,n;
    cin>>k;
    if(k==1){
	cout<<1<<endl;cout<<1<<endl;
	return 0;
    }
    n=(k+3)/4*2;
    cout<<n<<endl;
    lol(i,n/2){
	lol(j,n)a[i*2][(j+i*2)%n]=j;
	lol(j,n){
	    ll res=j;
	    if(n+j<k)res+=n;
	    a[i*2+1][(j+1+i*2)%n]=res;
	}
    }
    lol(i,n){
	lol(j,n){
	    if(j)cout<<" ";
	    cout<<a[i][j]+1;
	}cout<<endl;
    }
    return 0;
}
