 #include <iostream>
#define ll long long
using namespace std;
int main(void){
    // Your code here!
    ll k,n;
    cin>>k;
    n=(k+1)/2;
    n+=n%2;
    if(k==1){
        cout<<1<<endl<<1;
    }
    else{
    cout<<n<<endl;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(i%2==0){
                cout<<(i+j)%n+1<<" ";
            }
            else{
                if(n+(i+j)%n>=k){
                    cout<<(i+j)%n+1<<" ";
                }
                else{
                cout<<(n+(i+j)%n)+1<<" ";
                }
            }
        }
        cout<<endl;
    }
    }
}
