#K7086. Counting Mountain Segments

    ID: 33402 Type: Default 1000ms 256MiB

Counting Mountain Segments

Counting Mountain Segments

You are given a sequence of integers that represents the heights of a mountain range. A mountain segment is defined as a contiguous subarray where the numbers first strictly increase to a peak and then strictly decrease. Formally, for a contiguous subarray [a_l, a_{l+1}, \ldots, a_r], there exists an index p (\(l < p < r\)) such that:

[ a_l < a_{l+1} < \cdots < a_p \quad\text{and}\quad a_p > a_{p+1} > \cdots > a_r ]

Your task is to count the number of valid mountain segments in the given array.

Note: Two mountain segments are counted separately even if they overlap partially, as long as they satisfy the definition.

inputFormat

The input is given via stdin and consists of two lines:

  • The first line contains a single integer N (\(1 \leq N \leq 10^5\)) representing the number of elements in the sequence.
  • The second line contains N space-separated integers representing the mountain heights.

outputFormat

Print a single integer to stdout – the number of mountain segments in the given array.

## sample
10
2 1 4 7 3 2 5 6 4 3
2