#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL a[505][505];

int main(){
	ios::sync_with_stdio(false);
	LL n,k;
	cin >> k;
	
	n = min(500LL,k);
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= n;j ++){
			a[j][i] = i;
		}
	}
	if(k > 500){
		k -= 500;
		for(LL i = 1;i <= k;i ++){
			for(LL j = 2;j <= n;j += 2){
				a[j][i] += n;
			}
		}
	}
	
	cout << n << endl;
	for(LL i = 1;i <= n;i ++){
		for(LL j = i;j <= n;j ++) cout << a[i][j] << ' ';
		for(LL j = 1;j < i;j ++) cout << a[i][j] << ' ';
		cout << endl;
	}
	return 0;
}