souvenirs

Souvenirs

Artsem is on vacation and wants to buy souvenirs for his two teammates. There are n souvenir shops along the street. In ith shop Artsem can buy one souvenir for ai dollars, and he cannot buy more than one souvenir in one shop. He doesn't want to introduce envy in his team, so he wants to buy two souvenirs with least possible difference in price.

Artsem has visited the shopping street m times. For some strange reason on the ith day only shops with numbers from li to ri were operating (weird? yes it is, but have you ever tried to come up with a reasonable legend for a range query problem?). For each visit, Artsem wants to know the minimum possible difference in prices of two different souvenirs he can buy in the opened shops.

In other words, for each Artsem's visit you should find the minimum possible value of |asat| where lis,tri,st.

Limits

2n105
1m3105
0ai109
0lirin

Subtasks # Score Constraits
1 21 ai is in non-decreasing order
2 30 n1000
m1000
3 49 -

Input format

The first line contains n.

The next line contains n integers, where the ith integer represents ai

The next line contains m

The next m lines contains 2 integers, where the ith of these lines represents li and ri

Output format

Print the answer to each query in a separate line.

Samples

Sample Input 1 Sample Output 1
8
3 1 4 1 5 9 2 6
4
1 8
1 3
4 8
5 7
0
1
1
3


Submitting .cpp to 'souvenirs'


You're not logged in! Click here to login

Time Limit: 3 Seconds
Memory Limit: 1024MB
Your best score: 0
Source: Codeforces 765F
Editorial: 1

Subtask Score
1 21
2 30
3 49
4 0