#include <iostream>

using namespace std;

#define N 8

int knight_func(int x, int y, int movei, int result[N][N],

int xMove[], int yMove[]);

int check(int x, int y, int result[N][N])

{

return (x >= 0 && x < N && y >= 0 && y < N

&& result[x][y] == -1);

}

void result(int result[N][N])

{

for (int x = 0; x < N; x++) {

for (int y = 0; y < N; y++)

cout << " "<< result[x][y] << " ";

cout << endl;

}

}

int knight_func()

{

int result[N][N];

for (int x = 0; x < N; x++)

for (int y = 0; y < N; y++)

result[x][y] = -1;

int xMove[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };

int yMove[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };

result[0][0] = 0;

/* Start from 0,0 and explore all tours using

solveKTUtil() */

if (knight_func(0, 0, 1, result, xMove, yMove) == 0) {

cout << "false";

return 0;

}

else

(result);

return 0;

}

int knight_func(int x, int y, int movei, int result[N][N],

int xMove[N], int yMove[N])

{

int k, next_x, next_y;

if (movei == N * N)

return 1;

for (k = 0; k < 8; k++) {

next_x = x + xMove[k];

next_y = y + yMove[k];

if (check(next_x, next_y, result)) {

result[next_x][next_y] = movei;

if (knight_func(next_x, next_y, movei + 1, result,

xMove, yMove)

== 1)

return 1;

else

result[next_x][next_y] = -1;

}

}

return 0;

}

int main()

{

knight_func();

return 0;

}