Luka walks into the house of the witch Marica, and she starts questioning him about her array A of N numbers. Each question is a pair of integers L and R that marks the subarray running from AL to AR.
For every question Luka has to answer with the length of the longest magical subarray contained in that subarray. The whole queried subarray is allowed.
A subarray is magical when every value in it lies between its first value and its last value. That is, Al,Al+1,…,Ar is magical when min(Al,Ar)≤Ak≤max(Al,Ar) holds for every k with l≤k≤r.
For example, [1,3,1,2,4] and [4,1,1,2,1] are magical, while [3,3,4,1] is not. A subarray of length 1 is always magical, so every answer is at least 1.