#include <bits/stdc++.h>
using namespace std;

const int N = 500;
int n , k , col[N][N];
int main(){
	scanf("%d",&k);
	if (k == 1){
		return puts("1\n1") , 0;
	}
	n = ((k + 3) / 4) * 2;
	
	for (int i = 0;i < n;i++)
	for (int j = 0;j < n;j++){
		col[i][j] = (i + j) % n + ( (j & 1) ? n : 0);
		if (col[i][j] >= k) col[i][j] -= n;
	}
	
	
	printf("%d\n",n);
	for (int i = 0;i < n;i++){
		for (int j = 0;j < n;j++){
			printf("%d ",col[i][j]+1);
		}
		putchar('\n');
	}
    return 0;
}