logo AlgoBeat OnlineJudge
登录 注册

#217787. [JAG 2026 Summer Camp #1] Longest Symmetry

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

There are houses numbered on a number line. House is located at coordinate . It is guaranteed that for every ().

For integers with , we say that the consecutive houses form a symmetric interval of houses if the following condition holds:

  • For every , holds.

You are given queries. Process them in order.

  • In the -th query, you are given integers (). Among all pairs of integers satisfying such that the consecutive houses form a symmetric interval of houses, output the maximum possible width of the interval.

输入格式

The input consists of a single test case of the following format:

N
X_1 X_2 ... X_N
Q
l_1 r_1
l_2 r_2
...
l_Q r_Q

The first line contains an integer , representing the number of houses ().

The second line contains integers , representing the coordinates of the houses (). It is guaranteed that for every ().

The third line contains an integer , representing the number of queries ().

Each of the following lines contains two integers and , representing the left and right endpoints of the range specified in the -th query ().

输出格式

For each query, output the maximum possible width.

样例

样例输入 1

7
-5 -2 0 4 6 9 12
5
1 7
2 6
3 7
4 7
3 6

样例输出 1

14
8
6
6
4