The chess problem.
During the algorithms exam, Petrik got an unlucky problem, so he asks for your help. You are given the standard chessboard , whose cells are numbered from left to right from to and from bottom to top from 1 to 8. Among the white pieces on the board, there can be all types of pieces except the king, while among the black pieces, on the contrary, there is only one king. It is also known that the pieces are placed absolutely arbitrarily, that is, their placement may not be subject to the standard rules of chess (white ones can even have too many pieces of a certain type). Your task is to determine the position of the black player: checkmate, stalemate, or a normal position.
Chess rules:
Check — a tactical move in which an attack is made on the opponent's king.
Checkmate — a situation in which the king is under attack, and the player has no possible move after which the king would not be under attack.
Stalemate — a situation in which the side that should move cannot do so, because all of its pieces are unable to make a move, while the king is not under attack.
Rules for attacking / moving pieces within the problem:
Queen — attacks on the verticals, diagonals, and horizontals on which it is located, but it cannot jump over other pieces.
Rook — attacks on the vertical and horizontal on which it is located, but it cannot jump over other pieces.
Bishop — attacks on the diagonals on which it is located, but it cannot jump over other pieces.
Knight — a knight's move consists of strictly two moves: one field vertically or horizontally, then moving away from the starting field one field diagonally. This is the only piece that can jump over other pieces.
Pawn — attacks diagonally one cell towards the opponent (thus, white pawns always attack only diagonally upwards).
King — moves from its field to one of the adjacent free fields (including diagonals) that are not under attack by the opponent's pieces. Can attack a piece that is on an adjacent field if it is not under attack.
Input
The input data contains 8 lines, each of which consists of 8 characters. Each character indicates the corresponding cell on the chessboard:
the character «
.
» indicates an empty cellthe character «
p
» indicates a pawnthe character «
r
» indicates a rookthe character «
n
» indicates a knightthe character «
b
» indicates a bishopthe character «
Q
» indicates a queenthe character «
K
» indicates a king
It is guaranteed that there is exactly one king.
Output
If the king is in checkmate, output «Checkmate
» in the first line, and output all the pieces that attack it in any order in the following lines.
If the king is in stalemate, output «Stalemate
» on the first line.
Otherwise, output «Continue
» and all the cells in which the king can make a move in any order.