Reversi
Once upon a time, at 12 o'clock in the morning, a teacher at LKS awoke to find that a quest was underway at the school. Unsurprisingly, he was quickly surrounded by students eager for clues.
To buy some time to devise a new and exciting contest, he needed to keep the students engaged. He then noticed a set for the game "Reversi." The rules of this game are straightforward: on an 8×8 board, two players alternate placing one piece of their color on an empty square. After each move, the player searches in each of the 8 directions from the new piece for the nearest piece of their color. If there are no empty squares between them, all the opponent's pieces lying between them are flipped to the player's color. For instance, if the black pieces move to square A (see fig.), then five white pieces, marked in gray in the figure on the right, will turn black.
A move is only permitted if at least one of the opponent's pieces will be flipped to the player's color after the move (for example, moves to squares B and C are not allowed). The objective of the game is to have the most pieces of your color at the end, but the teacher doesn't have time to play (he still needs to think of a contest). So, he arranged a specific position on the board (not necessarily possible in a real game) and asked the students to count the number of positions (also possibly not real) from which a single move by either white or black could result in the given position.
Help write a program that calculates the answer to this contest, as time is precious!
Input
The input file contains 8 rows with 8 characters each. The character "B" represents a black piece; "W" represents a white piece; "." represents an empty position.
Output
In a single line of the output file, print a single integer - the number of positions sought.