#include <iostream>
using namespace std;
const int row[8] = {-2, -1, +1, +2, +2, +1, -1, -2};
const int col[8] = {+1, +2, +2, +1, -1, -2, -2, -1};
void try2Move(int count, int x, int y, int** board, int n);
void printAns(int** board, int n);
bool isInBoard(int x, int y, int n);
int main() {
int n;
cin >> n;
int** board = new int*[n]();
for(int i=0; i<n; i++)
board[i] = new int[n]();
int x, y;
cin >> x >> y;
board[x][y] = 1;
try2Move(2, x, y, board, n);
for(int i=0; i<n; i++)
delete[] board[i];
delete[] board;
return 0;
}
void printAns(int** board, int n) {
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
cout << board[i][j] << " ";
}
cout<<"\n";
}
}
bool isInBoard(int x, int y, int n) {
if(x < 0 || x >= n) return false;
if(y < 0 || y >= n) return false;
return true;
}
//===============================================================
bool checkAns = false;
bool nextCellIsFirstCell(int x, int y, int** board, int n) {
for (int i=0; i<8; i++) {
int xN = x + row[i];
int yN = y + col[i];
if(!isInBoard(xN, yN, n)) continue;
if(board[xN][yN] == 1)
return true;
}
return false;
}
void try2Move(int count, int x, int y, int** board, int n) {
if(checkAns == true) return;
if(count > n*n) {
if(!nextCellIsFirstCell(x, y, board, n)) return;
printAns(board, n);
checkAns = true;
}
for (int i=0; i<8; i++) {
int xN = x + row[i];
int yN = y + col[i];
//checking:
// (1) if the next cell is valid
// (2) check if the next cell is visited
if(!isInBoard(xN, yN, n)) continue;
if(board[xN][yN] != 0) continue;
board[xN][yN] = count;
try2Move(count+1, xN, yN, board, n);
board[xN][yN] = 0;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCByb3dbOF0gPSB7LTIsIC0xLCArMSwgKzIsICsyLCArMSwgLTEsIC0yfTsKY29uc3QgaW50IGNvbFs4XSA9IHsrMSwgKzIsICsyLCArMSwgLTEsIC0yLCAtMiwgLTF9OwoKdm9pZCB0cnkyTW92ZShpbnQgY291bnQsIGludCB4LCBpbnQgeSwgaW50KiogYm9hcmQsIGludCBuKTsKdm9pZCBwcmludEFucyhpbnQqKiBib2FyZCwgaW50IG4pOwpib29sIGlzSW5Cb2FyZChpbnQgeCwgaW50IHksIGludCBuKTsKCmludCBtYWluKCkgewogICAgaW50IG47CiAgICBjaW4gPj4gbjsKICAgIAogICAgaW50KiogYm9hcmQgPSBuZXcgaW50KltuXSgpOwogICAgZm9yKGludCBpPTA7IGk8bjsgaSsrKQogICAgICAgIGJvYXJkW2ldID0gbmV3IGludFtuXSgpOwogICAgCiAgICBpbnQgeCwgeTsKICAgIGNpbiA+PiB4ID4+IHk7CiAgICAKICAgIGJvYXJkW3hdW3ldID0gMTsKICAgIHRyeTJNb3ZlKDIsIHgsIHksIGJvYXJkLCBuKTsKICAgIAogICAgZm9yKGludCBpPTA7IGk8bjsgaSsrKQogICAgICAgIGRlbGV0ZVtdIGJvYXJkW2ldOwogICAgZGVsZXRlW10gYm9hcmQ7CiAgICAKICAgIHJldHVybiAwOwp9Cgp2b2lkIHByaW50QW5zKGludCoqIGJvYXJkLCBpbnQgbikgewogICAgZm9yKGludCBpPTA7IGk8bjsgaSsrKSB7CiAgICAgICAgZm9yKGludCBqPTA7IGo8bjsgaisrKSB7CiAgICAgICAgICAgIGNvdXQgPDwgYm9hcmRbaV1bal0gPDwgIiAiOwogICAgICAgIH0KICAgICAgICBjb3V0PDwiXG4iOwogICAgfQp9Cgpib29sIGlzSW5Cb2FyZChpbnQgeCwgaW50IHksIGludCBuKSB7CiAgICBpZih4IDwgMCB8fCB4ID49IG4pIHJldHVybiBmYWxzZTsKICAgIGlmKHkgPCAwIHx8IHkgPj0gbikgcmV0dXJuIGZhbHNlOwogICAgcmV0dXJuIHRydWU7Cn0KCi8vPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Cgpib29sIGNoZWNrQW5zID0gZmFsc2U7Cgpib29sIG5leHRDZWxsSXNGaXJzdENlbGwoaW50IHgsIGludCB5LCBpbnQqKiBib2FyZCwgaW50IG4pIHsKICAgIGZvciAoaW50IGk9MDsgaTw4OyBpKyspIHsKICAgICAgICBpbnQgeE4gPSB4ICsgcm93W2ldOwogICAgICAgIGludCB5TiA9IHkgKyBjb2xbaV07CiAgICAgICAgaWYoIWlzSW5Cb2FyZCh4TiwgeU4sIG4pKSBjb250aW51ZTsKICAgICAgICAKICAgICAgICBpZihib2FyZFt4Tl1beU5dID09IDEpCiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgfQogICAgcmV0dXJuIGZhbHNlOwp9Cgp2b2lkIHRyeTJNb3ZlKGludCBjb3VudCwgaW50IHgsIGludCB5LCBpbnQqKiBib2FyZCwgaW50IG4pIHsKICAgIGlmKGNoZWNrQW5zID09IHRydWUpIHJldHVybjsKICAgIGlmKGNvdW50ID4gbipuKSB7CiAgICAgICAgaWYoIW5leHRDZWxsSXNGaXJzdENlbGwoeCwgeSwgYm9hcmQsIG4pKSByZXR1cm47CiAgICAgICAgcHJpbnRBbnMoYm9hcmQsIG4pOwogICAgICAgIGNoZWNrQW5zID0gdHJ1ZTsKICAgIH0KICAgIAogICAgZm9yIChpbnQgaT0wOyBpPDg7IGkrKykgewogICAgICAgIGludCB4TiA9IHggKyByb3dbaV07CiAgICAgICAgaW50IHlOID0geSArIGNvbFtpXTsKICAgICAgICAKICAgICAgICAvL2NoZWNraW5nOgogICAgICAgIC8vICgxKSBpZiB0aGUgbmV4dCBjZWxsIGlzIHZhbGlkCiAgICAgICAgLy8gKDIpIGNoZWNrIGlmIHRoZSBuZXh0IGNlbGwgaXMgdmlzaXRlZAogICAgICAgIGlmKCFpc0luQm9hcmQoeE4sIHlOLCBuKSkgY29udGludWU7CiAgICAgICAgaWYoYm9hcmRbeE5dW3lOXSAhPSAwKSBjb250aW51ZTsKICAgICAgICAKICAgICAgICBib2FyZFt4Tl1beU5dID0gY291bnQ7CiAgICAgICAgdHJ5Mk1vdmUoY291bnQrMSwgeE4sIHlOLCBib2FyZCwgbik7CiAgICAgICAgYm9hcmRbeE5dW3lOXSA9IDA7CiAgICB9Cn0=