Let v be a sequence of length K. In one step, you can select an index i and change the value vi to either vi−1 or vi+1. Let f(v1,v2,…,vK) be the minimum number of steps required to satisfy v1≤v2≤⋯≤vK.
You are given an array s of length N. You are required to answer Q independent queries of the type: For given pair (l,r), what is the value of f(sl,sl+1,…,sr)?
Input format
Output format
Print Q lines where the ith line represents the answer for the ith query.
Additional information
For 20 points: N,Q≤512 is satisfied
For additional 30 points: N≤216,Q≤214 are satisfied
Original constraints for remaining points
The queries are (1,5),(1,3),(2,5).
In the first query, the optimal cost is achieved by obtaining sequence (3,3,3,3,3) or (2,2,3,3,3) etc.
In the second query, the optimal cost is achieved by obtaining sequence (4,4,4).
In the third query, the optimal cost is achieved by obtaining sequence (1,3,3,3)