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

int main() {
	int K;
	cin >> K;
	if (K == 1) {
		cout << 1 << endl << 1 << endl;
		return 0;
	}
	int N = ((K + 3) / 4) * 2;
	vector<vector<int> > ANS(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i % 2 == 0) ANS[i][j] = (j - i + N) % N + 1;
			else ANS[i][j] = (j - i + N) % N + N + 1;
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (ANS[i][j] > K) ANS[i][j] -= N;
		}
	}
	cout << N << endl;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cout << ANS[i][j];
			if (j == N - 1) cout << endl;
			else cout << ' ';
		}
	}
}