P1317 Depressions
Description
A sequence of numbers represents the ground profile’s elevation changes. The height values are integers, and adjacent heights are connected by straight line segments. Find and count how many low-lying depressions could hold water.
As shown: the elevation changes are $[0,1,0,2,1,2,0,0,2,0]$.

Input Format
Two lines.
- Line 1: $n$, the number of heights.
- Line 2: $n$ integers giving the ground profile heights, with the first and last equal to $0$. $(3 \le n \le 10000, 0 \le$ height $\le 1000)$.
Output Format
A single integer: the number of depressions that can potentially hold water.
Explanation/Hint
Translated by ChatGPT 5