#include using namespace std; using ll = long long; int main(){ int N, Y, X, V; cin >> N >> X >> Y >> V; X--, Y--; vector> A(N, vector(N)); int cnt = 1; vector> B = {{1,0,0,1},{0,1,1,0},{0,1,1,0},{1,0,0,1}}; for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ A[i][j] = (B[i % 4][j % 4] ? i * N + j + 1: N * N - (i * N + j)); } } auto f = [&](vector> &C){ vector S(N + N + 2); for(int y = 0; y < N; y++){ for(int x = 0; x < N; x++){ S[y] += C[y][x]; S[x + N] += C[y][x]; } S[N + N] += C[y][y]; S[N + N + 1] += C[y][N - 1 - y]; } return (count(S.begin(), S.end(), S[0]) == S.size()); }; auto rotate = [&](vector> &C){ vector> D(N, vector(N)); for(int y = 0; y < N; y++){ for(int x = 0; x < N; x++){ D[x][N - 1 - y] = C[y][x]; } } C = D; }; auto answer = [&](vector> &C){ for(int y = 0; y < N; y++){ for(int x = 0; x < N; x++){ cout << C[y][x] << (x + 1 == N ? '\n' : ' '); } } exit(0); }; for(int dy = 0; dy <= N; dy += 2){ for(int dx = 0; dx <= N; dx += 2){ vector> C(N, vector(N)); for(int y = 0; y < N; y++){ for(int x = 0; x < N; x++){ C[(y + dy) % N][(x + dx) % N] = A[y][x]; } } if(!f(C))continue; if(C[Y][X] == V)answer(C); rotate(C); if(C[Y][X] == V)answer(C); rotate(C); if(C[Y][X] == V)answer(C); rotate(C); if(C[Y][X] == V)answer(C); } } }