#t150. 山之谷

山之谷

Mountain Valleys

Problem Description

There is a mountainous area, which can be viewed as a grid with NN rows and MM columns. The altitude at row ii, column jj is hi,jh_{i,j}.

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 88 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 22 integers N,MN, M, the size of the mountainous area.

The following NN lines each contain MM integers hi,1,hi,2,…,hi,Mh_{i,1}, h_{i,2}, \dots, h_{i,M}, the altitudes.

Output Format

Output 11 line containing 11 integer CC, 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 3×53 \times 5 grid, there are 33 valleys in total, located at positions (2,2)(2,2) (altitude 55), (3,2)(3,2) (altitude 55), and (2,5)(2,5) (altitude 66). Each of these positions has an altitude not greater than that of its surrounding cells (up to 88 neighbors).

Constraints

1≤N,M≤1001 \le N, M \le 100 and 1≤hi,j≤1051 \le h_{i,j} \le 10^5 are guaranteed.