Sequence and Queries
InterviewTime limit1sMemory limit1024 MB
Count triples (i, j, k) where the length-k runs starting at positions i and j satisfy s[i+t] <= s[j+t] for every offset t below k.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
A sequence of length is given. The function is defined as follows.
Print the value of the following sum.
Input
The first line contains the integer , the length of the sequence.
The second line contains integers , separated by spaces.
Output
Print the value of .
Constraints
- ()
Hint
When , the inequality holds for every , so is always 1.