You are given a permutation
PPP of length
nnn. Find the number of its subsegments
[l…r][l\dots r][l…r](
l≤rl \le rl≤r) that satisfies the following condition:
-
∀1≤i≤r−l+1\forall 1\le i \le r-l+1∀1≤i≤r−l+1 , the iii-th element of this subsegment (that is, Pl+i−1P_{l+i-1}Pl+i−1) is not the iii-th smallest element in this subsegment.