#P11121. Counting Bitonic Subarrays
Counting Bitonic Subarrays
Counting Bitonic Subarrays
A sequence is called bitonic if there exists an index () such that [ a_1 \leq a_2 \leq \dots \leq a_m \quad \text{and} \quad a_m \geq a_{m+1} \geq \dots \geq a_n. ] Note that a strictly increasing or strictly decreasing sequence is also considered bitonic.
Given a sequence, count the number of pairs with such that the subarray is bitonic.
inputFormat
The first line contains an integer , the length of the sequence. The second line contains space-separated integers .
outputFormat
Output the number of pairs such that the subarray is bitonic.
sample
3
1 2 1
5
</p>