#K64672. Peak Climb Counter

    ID: 32028 Type: Default 1000ms 256MiB

Peak Climb Counter

Peak Climb Counter

You are given an elevation map for multiple test cases. Each test case consists of an integer n representing the number of points in the elevation sequence followed by n space-separated integers denoting the elevation at each point.

A Peak Climb is defined as a subsequence that first strictly increases and then immediately strictly decreases. Formally, given an elevation sequence \(a_1, a_2, \dots, a_n\), a valid peak climb occurs if there exists an index \(i\) with \(1 < i < n\) such that:

\[ a_1 < a_2 < \cdots a_{i+1} > \cdots > a_n \]

Your task is to determine the number of complete peak climbs in each test case. Note that the climb must be complete. Partial ascents or descents do not count.

Input is read from stdin and output is written to stdout as described below.

inputFormat

The first line of input contains a single integer t (1 ≤ t ≤ 105), the number of test cases. The description of each test case follows:

  • The first line of a test case contains an integer n (1 ≤ n ≤ 105), the number of elevation points.
  • The second line contains n space-separated integers representing the elevation points.

The total number of elevation points over all test cases does not exceed 106.

outputFormat

For each test case, output a single line containing an integer: the number of complete peak climbs found in the corresponding elevation map.

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

0 1

</p>