ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

1516. Nostalgia

Time limit: 1.0 second
Memory limit: 64 MB

Background

In nice city Uryupinsk on account of the grand opening of the new Culture Palace "Кolkhoznik" it was decided to organize an international draughts tournament. The best players from Berdichev, Zhmerinka and Tmurarakan as well as famous grand master O. Bender from Albania attended the tournament.

Problem

A game between Mr. Bender and the president of local kolkhoz "Lenin's way" Veniamin Goatman was recognized as the most interesting event of the tournament. The grand master played white, and the president played black. After his opponent's regular move, Mr. Bender declared, that he will win the game by taking all black draughts in one move. Mr. Goatman examined the position carefully and offered to bet the grand master a bottle of mineral water "Essentuki", that it was impossible.
The president did not expect Mr. Bender to be a master of some unique technique, which was an ability to filch secretly any number of draughts of any color from the board. To the grand master's credit, it should be noticed, that he tries to play fair and square and always filches the minimal number of draughts. How many draughts should Mr. Bender filch this time?

Input

Each of 8 lines contains 8 characters, which are the corresponding cells of the board. Character "W" means a white draught, character "B" means a black draught, and character "." (full stop) means an empty cell. There are not less than one and not more than twelve draughts of each color on the board. All the draughts are situated in the cells of the same color. White draughts, that reached the eighth horizontal, as well as black draughts, that reached the first horizontal, are considered as draughts anyway, i.e. there are no kings here.

Output

You should output the desired number of draughts.

Sample

inputoutput
W.......
.W......
..B...B.
.....W..
..B.B...
........
........
........
1

Notes

A draught-board is a black-and-white board 8*8 cells in size. A cell in its left-bottom corner has coordinates (1, 1) and a cell in its right-top corner has coordinates (8, 8). A cell with coordinates (x, y) is white if (x+y) modulo 2 = 1, otherwise it is black.
In one move, a draught may take any number of opponent's draughts one after another. A draught located in a cell with coordinates (xi, yi) may take an opponent's draught located in a cell with coordinates (xj, yj), if abs(xj-xi) = abs(yj-yi) = 1, and 2 ≤ xj ≤ 7, 2 ≤ yj ≤ 7, and a cell with coordinates (2*xj-xi, 2*yj-yi) is empty. At that the draught moves from a cell with coordinates (xi, yi) into a cell with coordinates (2*xj-xi, 2*yj-yi), and taken opponent's draught leaves the board.
In the sample, Mr. Bender should secretly filch a black draught located in a cell with coordinates (7, 6) from the board. Then a white draught located in a cell with coordinates (6, 5) will eat the others black draughts located in cells with coordinates (5, 4), (3, 4) and (3, 6) one after another.
Problem Author: Nikita Rybak, Ilya Grebnov, Dmitry Kovalioff
Problem Source: Timus Top Coders: Third Challenge