PRA11: Radar Crabs // Advanced

 
Poseidon, the king of the Sea, needs your help to count the number of crabs in his army. Recently, he's taken several radar images of his troops in an enclosed room, but there are too many for him to manually count! He wants you to write a program to find the number of crabs (represented by enclosed rectangles) in the grid.

Given a grid from the radar images of Poseidon's crab army, return the number of crabs found. An enclosed rectangle may use the outer bounds of the grid as a side.

Input Format

The first line contains two integers, m and n, representing the size of the array. Following are n lines with m characters, either a "." or a "#"

Sample Input

30 15
........................#.....
........................#.....
........................#.....
.....######.............######
.....#....#....######.........
.....#....#....#....#.....#...
.....######....######.....#...
..........................####
..............................
######.....##############.....
#....#.....#............#.....
...........#............#.....
######.....##############.....
#....#....................####
######....................#...

Output Format

A single integer representing the count of enclosed rectangles.

Sample Output

6




You must be logged in to submit a solution.