#t150. 山之谷
山之谷
Mountain Valleys
Problem Description
There is a mountainous area, which can be viewed as a grid with rows and columns. The altitude at row , column is .
If a cell's altitude is not greater than the altitude of all of its neighboring cells (neighbors include up, down, left, right, and the four diagonals — up to directions in total), then the cell is called a valley.
Count how many valleys there are in the mountainous area.
Input Format
The first line contains integers , the size of the mountainous area.
The following lines each contain integers , the altitudes.
Output Format
Output line containing integer , the number of valleys.
Sample Input
3 5
7 6 6 7 9
6 5 6 7 6
6 5 7 8 9
Sample Output
3
Sample Explanation
In the given grid, there are valleys in total, located at positions (altitude ), (altitude ), and (altitude ). Each of these positions has an altitude not greater than that of its surrounding cells (up to neighbors).
Constraints
and are guaranteed.