In the early 19th century, the ruler Hoseyngulu Khan Sardar ordered a palace to be built on a plateau overseeing a beautiful river. The plateau is modeled as an n×m grid of square cells. The rows of the grid are numbered 0 through n−1, and the columns are numbered 0 through m−1. We refer to the cell in row i and column j (0≤i≤n−1,0≤j≤m−1) as cell (i,j). Each cell (i,j) has a specific height, denoted by a\[i]\[j].
Hoseyngulu Khan Sardar asked his architects to choose a rectangular area to build the palace. The area should not contain any cell from the grid boundaries (row 0, row n−1, column 0, and column m−1). Hence, the architects should choose four integers r_1, r_2, c_1, and c_2 (1≤r_1≤r_2≤n−2 and 1≤c_1≤c_2≤m−2), which define an area consisting of all cells (i,j) such that r_1≤i≤r_2 and c_1≤j≤c_2.
In addition, an area is considered valid, if and only if for every cell (i,j) in the area, the following condition holds:
The height of cell (i,j) should be strictly smaller than the heights of all these four cells.
Your task is to help the architects find the number of valid areas for the palace (i.e., the number of choices of r_1, r_2, c_1 and c_2 that define a valid area).