#K45372. Counting Mountain Valleys

    ID: 27739 Type: Default 1000ms 256MiB

Counting Mountain Valleys

Counting Mountain Valleys

The problem asks you to determine the number of "mountain valleys" in an array of heights. A mountain valley is defined as a contiguous subarray a[l...r] (with 1 \le l < r \le n) in which there exists an index m such that

[ a[l] > a[l+1] > \cdots > a[m] \quad \text{and} \quad a[m] < a[m+1] < \cdots < a[r] ]

Your task is to count the number of such valleys for each test case.

Note: A valid valley must have at least three elements.

inputFormat

The first line of input contains an integer t representing the number of test cases. Each test case consists of two lines:

  1. The first line contains an integer n, the number of elements in the array.
  2. The second line contains n space-separated integers representing the height values.

outputFormat

For each test case, output a single integer on a new line representing the count of mountain valleys in the array.

## sample
2
5
10 8 7 12 15
4
1 2 3 4
1

0

</p>