module main; // https://kmjp.hatenablog.jp/entry/2015/06/05/0900 より import std; void main() { // 入力 int N, X, Y, Z; readln.chomp.formattedRead("%d %d %d %d", N, X, Y, Z); X--, Y--, Z--; // 答えの計算 auto ans = new int[][](N, N); foreach (y; 0 .. N) foreach (x; 0 .. N) { int tx = x % 4, ty = y % 4; if ((tx % 3 == 0) ^ (ty % 3 == 0)) ans[y][x] = (N - y) * N - x - 1; else ans[y][x] = y * N + x; } int xorv = Z ^ ans[Y][X]; foreach (y; 0 .. N) foreach (x; 0 .. N) ans[y][x] = (ans[y][x] ^ xorv) + 1; // 答えの出力 writefln("%(%(%d %)\n%)", ans); }