N Queens
Hardjavapythonccppjavascript
Count the number of distinct ways to 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).
Input Format
A single line containing the integer N.
Output Format
Print the number of valid arrangements.
Example 1
Input
4
Output
2
Explanation: For a 4x4 board there are exactly two valid arrangements.
- 1 <= N <= 12