Time limit
1s
Memory limit
128 MB
There is an N × N chessboard, where 6 ≤ N ≤ 666. A knight starts from the given square and must visit every square of the board exactly once using only legal knight moves. A square that has already been visited cannot be visited again.
The first line contains the integer N. The second line contains two integers r and c, the starting position. r is the row number and c is the column number, and coordinates are 1-based.
If such a route exists, print N × N lines containing the visited positions in order. Each line must contain the row number and column number separated by a space. If no route exists, print -1 -1 on the first line.