15018 - Long Live The King   

Description

The royal castle has been invaded!

The King is surrounded by enemy Rooks and Bishops, and he needs to escape before it is too late. Luckily, the King can still move one square in any of the 8 directions around him, just like in chess.

However, not every square is safe.

Just like in chess, an enemy Rook attacks horizontally and vertically, while an enemy Bishop attacks diagonally. Both pieces continue attacking in a direction until they reach the edge of the board or another piece blocks their path (except the king).

Your task is to determine how many safe squares the King can move to. His current position is not counted.

The board contains:

  • K the king
  • R an enemy rook
  • B an enemy bishop
  • . an empty square

A safe square is defined as an empty square that is not attacked by the enemy rook or bishop.

(Note: The King cannot attack enemy rook/bishop)

Bishop Move Illustration

Rook Move Illustration

Sample Input #1 Illustration

Input

The input consists of exactly 8 lines, each line contains 8 characters, representing an 8 × 8 chessboard.

It is guaranteed that there will be exactly one K.

The board contains only the characters K, R, B, and .

Output

Output one integer representing the number of safe squares the King can move to

If there is no safe square, output Checkmate! 

Sample Input  Download

Sample Output  Download




Discuss