N-Queens

HardRecursion & Backtracking
Next
BacktrackingBit ManipulationRecursion

Place n queens on an n x n chessboard so that no two queens attack each other (no two share a row, column or diagonal). Print the number of distinct ways to do it.

Input

A single integer n.

Output

Print the number of distinct solutions.

Constraints

1 <= n <= 10

Example 1
Input
4
Output
2

There are exactly two arrangements on a 4 x 4 board.

Example 2
Input
1
Output
1

A single queen on a single square.

Hints

N-Queens - Hard Recursion & Backtracking Problem | Skill Shiksha