# include <cstdio>
# include <iostream>
# define R register int

using namespace std;

int n,k,x;

int main()
{
    scanf("%d",&k);
 	if(k==1) { printf("1\n1"); return 0; } 
    if(k%4==0) n=k/4;
    else n=k/4+1;
    n=2*n;
    printf("%d\n",n);
    for (R i=1;i<=n;++i)
    {
        for (R j=1;j<=n;++j)
        {
            if(i%2==0) x=(i+j-2+n)%n+n+1;
            else x=(i+j-2+n)%n+1;
            if(x>k) x-=n;
            printf("%d ",x);
        }
        printf("\n");
    }
    return 0;
}