import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int [] [] solve (int k)
{
	int n = (k + 1) / 2;
	n = (n + 1) / 2 * 2;

	auto a = new int [] [] (n, n);
	int x = 0;
	int y = 1;
	foreach (i; 0..n)
	{
		x -= 2;
		y -= 2;
		foreach (j; 0..n)
		{
			a[i][j] = (j & 1) ? x : y;
		}
	}

	auto b = new int [n * 2];
	if (k == 1)
	{
		b[] = 1;
	}
	else
	{
		int total = k;
		int p = n * 2;
		while (p > 0)
		{
			foreach (i; 0..1 + (p > total))
			{
				p -= 1;
				b[p] = total;
			}
			total -= 1;
		}
	}
	debug {writeln (b);}

	foreach (i; 0..n)
	{
		foreach (j; 0..n)
		{
			a[i][j] = b[a[i][j] + n * 2];
		}
	}

	return a;
}

void main ()
{
	int k;
	while (readf (" %s", &k) > 0)
	{
		auto res = solve (k);
		writeln (res.length);
		writefln ("%(%(%s %)\n%)", res);
	}
}
