Under construction

Still being built. Things may change

Road Construction

Time limit1.5sMemory limit256 MB

Summary
For each query range of the road, find the minimum number of K-length spells that make all segment heights equal, or -1 if that is impossible.
Level

Medium7 of 10

Topics
Array, Prefix sum, Math
Solved
No attempts yet

Problem

SciOI City's mayor, Sangryeol, wants to build a new road. The ground where he plans to build it is too bumpy, and compacting the ground alone is expected to take years. The land is a straight strip split into NN segments, whose heights may be equal or different. Heights can be negative. The state of the road is given by a sequence AA of length NN, where AiA_i is the height of the ii-th segment.

Fortunately, Sangryeol is a wizard who can cast a spell that raises or lowers the heights of KK consecutive segments by the same amount. KK is fixed.

For example, let N=5N = 5, K=2K = 2, and the road be as follows.

3 5 6 2 9

If Sangryeol casts a spell that raises the third and fourth segments by 2, the road changes as follows.

3 5 8 4 9

Sangryeol's spells can also reach beyond the ends of the road, and any part of a spell outside the road is ignored. For example, when K=3K = 3, a spell can be cast on the 0th, 1st, and 2nd segments. The spell on the 0th segment is ignored, so only the 1st and 2nd segments are affected.

Input

The first line contains NN, KK, and the number of candidate segments QQ. (1≤K≤N≤100,0001 \le K \le N \le 100{,}000, 1≤Q≤100,0001 \le Q \le 100{,}000)

The second line contains the sequence AA of length NN that describes the road. (−109≤Ai≤109-10^9 \le A_i \le 10^9)

Each of the next QQ lines contains a candidate segment. The ii-th candidate is given by two integers lil_i and rir_i, meaning it covers the segments from the lil_i-th to the rir_i-th of the road. (1≤li≤ri≤N1 \le l_i \le r_i \le N)

Output

For each candidate segment, print on its own line the minimum number of spells Sangryeol must cast. If the heights of the road segments cannot be made equal with spells, print −1-1.

Examples1

  1. Example 1

    Input
    5 2 3
    1 3 3 2 2
    1 2
    2 5
    1 4
    
    Expected output
    1
    1
    2