Write a program to print the lexicographically smallest way to place queens on an chessboard so that no queen threatens another queen.
Input consists of a natural number .
Mark the queens with a ‘Q’, and the empty positions with
a dot. Print the lexicographically smallest way (by rows, from top to
bottom, and assuming that a ‘Q’ is smaller than a dot) to
place
queens on an
chessboard so that no queen threatens another queen. If there is no
solution, print “NO SOLUTION”.
Input
20
Output
Q................... ..Q................. ....Q............... .Q.................. ...Q................ ............Q....... ..............Q..... ...........Q........ .................Q.. ...................Q ................Q... ........Q........... ...............Q.... ..................Q. .......Q............ .........Q.......... ......Q............. .............Q...... .....Q.............. ..........Q.........
Input
3
Output
NO SOLUTION