#K44652. Count Beautiful Trees

    ID: 27579 Type: Default 1000ms 256MiB

Count Beautiful Trees

Count Beautiful Trees

Given a sequence of trees represented by their heights, your task is to determine the number of beautiful trees in each test case. A tree (except for the first and the last) is considered beautiful if it satisfies one of the following conditions:

  • $$A_{i-1} A_{i+1}$$
  • $$A_{i-1} > A_i < A_{i+1}$$

In other words, the current tree is either a peak or a valley compared to its immediate neighbors.

You need to evaluate each test case independently and output the count of beautiful trees for each.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
N_1
A_1 A_2 ... A_{N_1}
N_2
A_1 A_2 ... A_{N_2}
...
N_T
A_1 A_2 ... A_{N_T}

Here, T is the number of test cases, and for each test case, the first line contains the integer N which is the number of trees. The next line contains N integers representing the heights of the trees in order.

outputFormat

For each test case, output a single integer on a new line: the count of beautiful trees.

The output should be written to standard output (stdout).

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

0 1

</p>