/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define ra read_alpha()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline char read_alpha() { char c = ge; while(!isalpha(c) && c != EOF) c = ge; return c; }
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

int nx[510];
int A[510][510];

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int k = ri;
	if(k <= 500) {
		cout << k << endl;
		for(int i = 1; i <= k; i++)
			for(int j = 1; j <= k; j++)
				printf("%d%c", i, " \n"[j == k]);
	} else {
		int n = 500, N = 0;
		for(int i = 1; i <= n; i++) nx[i] = i + 1;
		nx[n] = 1, cout << 500 << endl, k -= n;
		for(int i = 1; i <= n; i++) {
			int a = ++N, b = k ? ++N : N;
			k -= b - a;
			for(int x = 1, y = i; x <= n; x++, y = nx[y])
				A[x][y] = x & 1 ? a : b;
		}
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				printf("%d%c", A[i][j], " \n"[j == n]);
	}
	return 0;
}