#ARC060C. [ARC060E] 高橋君とホテル

[ARC060E] 高橋君とホテル

Score : 700700 points

Problem Statement

NN hotels are located on a straight line. The coordinate of the ii-th hotel (1iN)(1 \leq i \leq N) is xix_i.

Tak the traveler has the following two personal principles:

  • He never travels a distance of more than LL in a single day.
  • He never sleeps in the open. That is, he must stay at a hotel at the end of a day.

You are given QQ queries. The jj-th (1jQ)(1 \leq j \leq Q) query is described by two distinct integers aja_j and bjb_j. For each query, find the minimum number of days that Tak needs to travel from the aja_j-th hotel to the bjb_j-th hotel following his principles. It is guaranteed that he can always travel from the aja_j-th hotel to the bjb_j-th hotel, in any given input.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1L1091 \leq L \leq 10^9
  • 1Q1051 \leq Q \leq 10^5
  • 1xi<x2<...<xN1091 \leq x_i < x_2 < ... < x_N \leq 10^9
  • xi+1xiLx_{i+1} - x_i \leq L
  • 1aj,bjN1 \leq a_j,b_j \leq N
  • ajbja_j \neq b_j
  • N,L,Q,xi,aj,bjN,\,L,\,Q,\,x_i,\,a_j,\,b_j are integers.

Partial Score

  • 200200 points will be awarded for passing the test set satisfying N103N \leq 10^3 and Q103Q \leq 10^3.

Input

The input is given from Standard Input in the following format:

NN

x1x_1 x2x_2 ...... xNx_N

LL

QQ

a1a_1 b1b_1

a2a_2 b2b_2

:

aQa_Q bQb_Q

Output

Print QQ lines. The jj-th line (1jQ)(1 \leq j \leq Q) should contain the minimum number of days that Tak needs to travel from the aja_j-th hotel to the bjb_j-th hotel.

9
1 3 6 13 15 18 19 29 31
10
4
1 8
7 3
6 7
8 5
4
2
1
2

For the 11-st query, he can travel from the 11-st hotel to the 88-th hotel in 44 days, as follows:

  • Day 11: Travel from the 11-st hotel to the 22-nd hotel. The distance traveled is 22.
  • Day 22: Travel from the 22-nd hotel to the 44-th hotel. The distance traveled is 1010.
  • Day 33: Travel from the 44-th hotel to the 77-th hotel. The distance traveled is 66.
  • Day 44: Travel from the 77-th hotel to the 88-th hotel. The distance traveled is 1010.