Ammunition Storage | 프로그래밍의 벗 PivotOJ
PivotOJ

Ammunition Storage

시간 제한: 2000ms메모리 제한: 1024MB출처: ICPC Asia Tehran Regional Contest 2022BOJ 28229

문제

The Do-Barareh military area is like an n×m grid, each cell of which has a specific height. The commander of this military area is looking for a rectangular sub-area of this area, with width and height least 2, whose its four corner cells are higher than the rest of its cells. He plans to install watchtowers in the corners of this sub-area to monitor the entire sub-area and use it for ammunition storage. Your job is to help the commander to find out how many valid sub-areas there are to choose as the ammunition storage. You can assume cell heights are distinct.

입력

The first line of input contains two space-separated integers n and m (2 ⩽ n, m ⩽ 750). Each of the next n lines contains m space-separated integers showing the cell heights. It is guaranteed cell heights are distinct numbers between 1 and nm (inclusive).

출력

Print the number of valid sub-areas to be used as an ammunition storage.

예제

예제 1

입력
3 3
9 4 8
2 1 3
7 5 6
출력
7
코드를 제출하려면 로그인하세요.