import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.regex, std.conv, std.stdio, std.typecons; void main() { auto n = readln.chomp.to!int; int[][] a; if (n % 2 == 1) a = calc1(n); else if (n % 4 == 0) a = calc2(n); else a = calc3(n); a.each!(b => writeln(b.map!(to!string).join(" "))); } int[][] calc1(int n) { auto a = new int[][](n, n); auto x = n / 2 - 1, y = 1; auto k = 1; while (k <= n ^^ 2) { auto x2 = x + 1; auto y2 = y - 1; if (x2 >= n) x2 = 0; if (y2 < 0) y2 = n - 1; if (a[y2][x2] > 0) { y = y + 1; } else { x = x2; y = y2; } if (y >= n) y = 0; a[y][x] = k; ++k; } return a; } int[][] calc2(int n) { auto a = new int[][](n, n); foreach (i; 0..n) foreach (j; 0..n) if (i % 4 == j % 4 || i % 4 + j % 4 == 3) a[i][j] = i * n + j + 1; else a[n - i - 1][n - j - 1] = i * n + j + 1; return a; } int[][] calc3(int n) { auto a = new int[][](n, n); auto m = n / 2; auto b = calc1(m); b.each!((l) { l[] -= 1; l[] *= 4; }); foreach (i; 0..m) foreach (j; 0..m) { if (i <= m / 2 - 1 || i == m / 2 && j != m / 2 || i == m / 2 + 1 && j == m / 2) { a[i * 2][j * 2] = b[i][j] + 4; a[i * 2][j * 2 + 1] = b[i][j] + 1; } else { a[i * 2][j * 2] = b[i][j] + 1; a[i * 2][j * 2 + 1] = b[i][j] + 4; } if (i <= m / 2 + 1) { a[i * 2 + 1][j * 2] = b[i][j] + 2; a[i * 2 + 1][j * 2 + 1] = b[i][j] + 3; } else { a[i * 2 + 1][j * 2] = b[i][j] + 3; a[i * 2 + 1][j * 2 + 1] = b[i][j] + 2; } } return a; }