跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F0923. Souvenirs

    ID: 929 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 10 上传者: 标签>数据结构挑战难度共享题库Codeforces英文题面题目来源题面语言

Souvenirs

题目描述

F. Souvenirs
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Artsem is on vacation and wants to buy souvenirs for his two teammates. There are n souvenir shops along the street. In i-th 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 i-th 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 |as-at| where lis,tri, st.

Input

The first line contains an integer n (2≤n≤105).

The second line contains n space-separated integers a1, ..., an (0≤ai≤109).

The third line contains the number of queries m (1≤m≤3·105).

Next m lines describe the queries. i-th of these lines contains two space-separated integers li and ri denoting the range of shops working on i-th day (1≤li<rin).

Output

Print the answer to each query in a separate line.

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


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 358 题。保留原作者与原赛事署名。