#P1596. Counting Ponds

    ID: 14882 Type: Default 1000ms 256MiB

Counting Ponds

Counting Ponds

Farmer John's field is represented by an \(N \times M\) grid of squares (where \(1 \leq N, M \leq 100\)). Each square is either water ('W') or dry land ('.'). Due to recent rains, water has pooled in various places in the field. A pond is a connected set of water squares, where connectivity is defined over all eight neighbors (horizontally, vertically, and diagonally adjacent).

Your task is to determine the number of ponds in the field given the grid diagram.

inputFormat

The first line contains two integers \(N\) and \(M\), representing the number of rows and columns, respectively. This is followed by \(N\) lines, each containing a string of exactly \(M\) characters (each character is either 'W' or '.') representing one row of the field.

outputFormat

Output a single integer, the number of ponds in the field.

sample

3 3
W..
.W.
..W
1