e-olymp
favorite We need a little bit of your help to keep things running, click on this banner to learn more
Competitions

Marathon weekend with restrictions

Queen, rook and bishop

prb1117On the chessboard, the queen, rook and bishop of the same color. How many fields are under the board fight?

Rook (R) runs only on the horizontals and verticals, the Bishop (B) - only on the diagonals, Queen (Q) - goes on horizontals, verticals and diagonals.

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 - just an bishop. Yellow dots denote the field under battle queen and rook at the same time, brown - the queen and bishop at the same time, the blue dot denotes the field to the fight while under the bishop and the rook.

Input

In a single line in the international chess notation (see the example input data) are defined by a space position queen, rook and bishop (in no particular order). All input data is valid.

Output

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 Bg4
Output example #1
36
Source Stage II All-Ukrainian Olympiad 2010-2011 Berdichev