LearnPy Hub
← Recursion & Lambda problems
Hard

Count Queen Placements

Read n (1–8). Count the ways to place n queens on an n × n board so that no two attack each other, using recursion that places one queen per row and backtracks. Also print the first solution found (rows top to bottom, column of each queen from 0), or none.

Input

One integer.

Output

Two lines.

Sample 1

Input
4
Output
2
1 3 0 2

Sample 2

Input
1
Output
1
0
solution.py
Output appears here
Count Queen Placements · Python practice problem · LearnPy Hub