#K65297. Special Trees in the Woodland Belt
Special Trees in the Woodland Belt
Special Trees in the Woodland Belt
You are given a row of n trees, where each tree has a certain height. A tree at position i (with positions numbered from 1 to n) is considered a special tree if its height is strictly greater than the heights of its adjacent trees. In other words, for a tree at position i (where 2 ≤ i ≤ n-1), it is special if
$$h_i > h_{i-1} \quad \text{and} \quad h_i > h_{i+1}.$$
Your task is to count the number of special trees and output their positions in the row. Note that the first and the last trees are not considered.
inputFormat
The input is read from standard input (stdin
) and consists of two lines. The first line contains a single integer n (the number of trees). The second line contains n space-separated integers representing the heights of the trees.
outputFormat
Print the result to standard output (stdout
). The first line should contain the number of special trees. The second line should list the positions (1-indexed) of the special trees separated by a space. If there are no special trees, the second line should be empty.
5
1 3 2 5 4
2
2 4
</p>