Time limit
2s
Memory limit
128 MB
A white queen and two black kings are placed on a 100 x 100 chessboard. White and black move alternately, and the white queen moves first. On each black turn, exactly one of the two black kings moves.
The goal is for the white queen to move onto the square occupied by one of the two black kings and capture that king. Black tries to delay being captured for as long as possible. A king cannot capture the queen and cannot move onto the queen's square.
A king moves one square in one of the 8 horizontal, vertical, or diagonal directions. The queen moves any positive number of squares in one of those same 8 directions. Neither side may skip a turn, and no piece may move outside the board. Given the initial positions, find the minimum number of queen moves required to capture one king.
The first line contains the queen's position. The second and third lines contain the positions of the two kings.
Each position is given in the form row column. The top-left square is (0, 0), and the bottom-right square is (99, 99). Initially, the queen and a king are never on the same square, and the two kings are never on the same square.
Output the minimum number of queen moves required to capture one king.