Batman Returns
문제
Gotham City consists of a single street, and there are skyscrapers located along it. They are numbered from west to east with integers from to , the height of the -th skyscraper is equal to meters.
Every night Batman performs an observation flight over the city. He climbs on the roof of some skyscraper and glides down to the roof of some other skyscraper. Due to the strong permanent wind he is only able to flight westward, but his altitude remains almost the same. Thus, he is able to glide down from skyscraper to skyscraper if and only if and . Moreover, Batman is very manoeuvrable, so the height of the buildings between and don't matter. Batman cares a lot about the crime level in the city so he chooses such pair of valid and that is maximum possible.
City authorities have developed plans of city renewal. According to the -th plan only skyscrapers from to , inclusive will remain on this street, while others will be destroyed. For each plan Batman wants to know the optimal plan to observe the city, namely such and that , and is maximum possible.
입력
The first line of the input contains one integer () --- number of skyscrapers on the street.
The second line contains integers () --- heights of the skyscrapers.
Third line contains integer () --- the number of plans designed by the city authorities.
Each of the last lines contains two integers and (), denoting the range of the skyscrapers that will remain according to the -th plan.
출력
For each renewal plan you should print two integers --- optimal and . If there is no possible observation flight at all, you should print -1 -1.
If there are many optimal answers, you may print any one of them.
힌트
Consider the first sample test. In the first query the only two available skyscrapers have heights and but they are not valid since . In the second query the pair consisting of the first and the second skyscrapers is valid since they have heights and .
Consider the second sample test. In the first query the pair of skyscrapers with heights and , and the pair of skyscrapers with heights and are valid. The distance between first two of them is greater so this pair produces the answer for this query.
예제
예제 1
4 2 3 1 4 2 2 3 1 3
-1 -1 1 2
예제 2
7 5 4 2 4 3 1 5 4 2 6 2 7 1 7 3 7
3 5 2 7 2 7 3 7