Sandcastle 2

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

JOI-kun is playing on a sand beach. He makes a sandcastle. The sandcastle made by JOI-kun is contained in a rectangular region in the sand beach. The rectangular region consists of cells of HH horizontal rows and WW vertical columns. The cell in the ii-th row (1iH1 ≤ i ≤ H) from the north and the jj-th column (1jW1 ≤ j ≤ W) from the west has height A_i,jA\_{i,j}. Note that the values of A_i,jA\_{i, j} are different from each other.

To the sandcastle, JOI-kun performed the following actions.

  1. First, JOI-kun chose a cell, and he started moving from the chosen cell.
  2. Then, he moved from the current cell to an adjacent cell in one of the four direction. He had to move to a cell which is lower than the current cell. He repeated this zero or more times.

Finally, if we view the cells he visited from above, the cells form a rectangle.

Given the information of the height A_i,jA\_{i, j} of each cell, write a program which calculates the number of possible rectangles formed by the the cells JOI-kun visited.

입력

Read the following data from the standard input. Given values are all integers.

\begin{align\*}& H\\,W \\\ & A\_{1,1}\\,A\_{1,2} \\, \cdots \\, A\_{1,W} \\\ & A\_{2,1} \\, A\_{2,2} \\, \cdots \\, A\_{2,W} \\\ & \vdots \\\ & A\_{H,1} \\, A\_{H,2} \\, \cdots \\, A\_{H,W}\end{align\*}

출력

Write one line to the standard output. The output should contain the number of possible rectangles formed by the cells JOI-kun visited.

제한

  • H1H ≥ 1.
  • W1W ≥ 1.
  • H×W50,000H \times W ≤ 50\\,000.
  • 1A_i,j10,000,0001 ≤ A\_{i, j} ≤ 10\\,000\\,000 (1iH1 ≤ i ≤ H, 1jW1 ≤ j ≤ W).
  • A_i_1,j_1A_i_2,j_2A\_{i\_1, j\_1} \ne A\_{i\_2, j\_2} (1i_1H1 ≤ i\_1 ≤ H, 1j_1W1 ≤ j\_1 ≤ W, 1i_2H1 ≤ i\_2 ≤ H, 1j_2W1 ≤ j\_2 ≤ W, (i_1,j_1)(i_2,j_2)(i\_1, j\_1) \ne (i\_2, j\_2)).