Game Score
A square board of size n×n is provided. This board was used for an intellectual game, resulting in cells colored white, black, and green. The coloring pattern can vary, but the top row is entirely white, and the bottom row is entirely black. To determine the winner, you need to count the number of cells in the white and black areas.
The white area is defined as the largest possible section of the square, starting from the top side and enclosed by a continuous boundary of white cells. This boundary must not revisit any cell and consists of adjacent white cells (cells sharing a side). The boundary starts at the top left and ends at the top right cell of the square. Similarly, the black area is defined as the largest section starting from the bottom side, enclosed by a continuous boundary of black cells, beginning at the bottom left and ending at the bottom right cell of the square.
Write a program that, given the board's coloring, calculates the number of cells in both the white and black areas.
Input
The first line contains the size of the square n (5 ≤ n ≤ 250). Each of the following n lines contains n characters "G", "W", or "B" (without spaces), representing green, white, and black colors, respectively.
Output
The first line should display the number of cells in the white area, and the second line should display the number of cells in the black area.