eolymp
bolt
Try our new interface for solving problems
Problems

Queens in peaceful positions

Queens in peaceful positions

On a chessboard of size \textbf{N}×\textbf{N} (\textbf{N} ≤ \textbf{50}) \textbf{N} queens are placed. We'll say that queens are in peaceful position if none of them can attack another. You are to find the total amount of peaceful positions that can be obtained from the given peaceful position by rearranging of exactly three queens. \InputFile The first line of input will contain an integer number \textbf{N }that represents the size of a chessboard (and the number of queens also). It will be followed by \textbf{N }lines describing positions of queens. Each line will contain two integers \textbf{X }and \textbf{Y }separated by a space. These numbers represent horizontal and vertical coordinates and lay in a range from \textbf{1 }to \textbf{N}. \OutputFile The output consists of a single integer representing the number of peaceful positions that can be achieved from initial position by moving of exactly three queens. Note: queens are not numbered so if you rearrange them on the chessboard using only squares they already occupied you’ll always get the same peaceful position, not the new one.
Time limit 1 second
Memory limit 64 MiB
Input example #1
4
2 1
4 2
1 3
3 4
Output example #1
0
Author Dmitry Filimonenkov
Source 1999 III Ural Collegiate Programming Contest, Ekaterinburg, March 19 - 20, Problem G