cho.sh
Notes
Loading...

War - Battle

Time limit

2s

Memory limit

128 MB

Problem

The battlefield is filled with our soldiers in white uniforms and enemy soldiers in blue uniforms. Even in the confusion, each soldier's team can be identified by uniform color.

When soldiers from the same team are connected vertically or horizontally, they form one group. If a group contains K soldiers, its power is K^2. Soldiers touching only diagonally are not in the same group.

Compute the total power of our soldiers and the total power of the enemy soldiers.

Input

The first line contains the battlefield width N and height M. (1 <= N, M <= 100)

The next M lines each contain the uniform colors of the soldiers in that row, with no spaces. W means white and B means blue. Every cell contains exactly one soldier, and at least one soldier of each color exists.

Output

Print two integers on the first line: the total power of our soldiers and the total power of the enemy soldiers, separated by a space.