Best Grass

No attempts yetTime limit1sMemory limit128 MB

Problem

Bessie is planning a day of munching tender spring grass and gazes out over the pasture, which Farmer John has partitioned into a grid with $R$ rows and $C$ columns. She wants to count the number of grass clumps in the pasture.

On the map, each grass clump appears either as a single # symbol, or as two # symbols placed directly side by side — horizontally or vertically, but never on a diagonal. No two symbols that belong to different clumps are ever adjacent (sharing an edge). Given the map of the pasture, report how many grass clumps there are.

Constraints:

  • $1 \le R \le 100$
  • $1 \le C \le 100$

Input

  • Line 1: two space-separated integers $R$ and $C$.
  • Lines 2 to $R+1$: line $i+1$ describes row $i$ of the pasture as $C$ characters, each either # or ..

Output

  • A single integer: the number of grass clumps in the pasture.