#K61242. Scenic Hikes
Scenic Hikes
Scenic Hikes
You are given a hiking trail with n points, each having a specified altitude. A scenic hike is defined as any subarray of three consecutive points in which the altitude first increases and then decreases. Mathematically, for three consecutive points a, b, c, the hike is scenic if and only if \(a c\).
Your task is to count the number of scenic hikes in the given trail.
Note: The input is provided via stdin
and the output should be printed to stdout
.
inputFormat
The first line of input contains a single integer n (\(3 \leq n \leq 10^6\)), the number of points on the trail.
The second line contains n space-separated integers representing the altitudes at these points.
outputFormat
Output a single integer representing the number of scenic hikes (i.e., the number of valid peak formations).
## sample5
1 3 2 4 5
1
</p>