eolymp
bolt
Try our new interface for solving problems
Problems

Queen, Rook and Knight

Queen, Rook and Knight

\includegraphics{https://static.e-olymp.com/content/11/11c4c6c0b83d18598962d913e09c197aa8b59561.jpg} On the chessboard, the queen, rook and a knight of the same color. How many fields are under the board fight? Rook (\textbf{R}) runs only on the horizontals and verticals, the knight (\textbf{N}) - two squares in one direction and one to the other (the letter "\textbf{Г}"), Queen (\textbf{Q}) - goes on horizontals, verticals and diagonals. By the way, the knight - the only chess piece that in its course can jump both through itself and the enemy's pieces. The figure with red dots show the field that are under the gun (in chess terms - under the battle), only the queen, blue - just a rook, green - only a knight. Yellow dots denote the field under battle queen and rook at the same time, brown - the queen and the knight at a time. \InputFile In a single line in the international chess notation (see the example input data) are defined by a space position queen, knight and rook (in no particular order). All input data is valid. \OutputFile Derive a single number - the number of checkerboard fields under their "target".
Time limit 1 second
Memory limit 64 MiB
Input example #1
Qe5 Rg7 Ng4
Output example #1
34
Source Stage II All-Ukrainian Olympiad 2010-2011 Berdichev