Problem: There are N points on a number line, i-th of which is placed on coordinate X_i. These points are numbered in the increasing order of coordinates. In other words, for all i (1 \leq i \leq N-1), X_i < X_{i+1} holds. In addition to that, an integer K is given.

Process Q queries.

In the i-th query, two integers L_i and R_i are given. Here, a set s of points is said to be a good set if it satisfies all of the following conditions. Note that the definition of good sets varies over queries.

* Each point in s is one of X_{L_i},X_{L_i+1},\ldots,X_{R_i}.
* For any two distinct points in s, the distance between them is greater than or equal to K.
* The size of s is maximum among all sets that satisfy the aforementioned conditions.



For each query, find the size of the union of all good sets.

Constraints

* 1 \leq N \leq 2 \times 10^5
* 1 \leq K \leq 10^9
* 0 \leq X_1 < X_2 < \cdots < X_N \leq 10^9
* 1 \leq Q \leq 2 \times 10^5
* 1 \leq L_i \leq R_i \leq N
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N K
X_1 X_2 \cdots X_N
Q
L_1 R_1
L_2 R_2
\vdots
L_Q R_Q


Output

For each query, print the size of the union of all good sets in a line.

Examples

Input

5 3
1 2 4 7 8
2
1 5
1 2


Output

4
2


Input

15 220492538
4452279 12864090 23146757 31318558 133073771 141315707 263239555 350278176 401243954 418305779 450172439 560311491 625900495 626194585 891960194
5
6 14
1 8
1 13
7 12
4 12


Output

4
6
11
2
3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mxn = 2e5 + 5;
int n, K, q;
int x[mxn];
int l[mxn], r[mxn];
int idl[mxn], idr[mxn];
int mx[mxn];
ll sum[mxn];
int jmp[mxn][20];
ll s[mxn][20];

bool cmpl(int a, int b) {
	return l[a] > l[b];
}

bool cmpr(int a, int b) {
	return r[a] < r[b];
}

int main() {
	scanf("%d %d", &n, &K);
	rep(i, n) scanf("%d", &x[i]);
	scanf("%d", &q);
	rep(i, q) {
		scanf("%d %d", &l[i], &r[i]);
		-- l[i], -- r[i];
		idl[i] = idr[i] = i;
	}
	sort(idl, idl + q, cmpl);
	sort(idr, idr + q, cmpr);
	int i = 0;
	rep(R, n) {
		jmp[R][0] = upper_bound(x, x + n, x[R] - K) - x - 1;
		s[R][0] = R + 1;
		for (int j = 1; j < 20; ++ j) {
			jmp[R][j] = jmp[R][j - 1] == -1 ? -1 : jmp[jmp[R][j - 1]][j - 1];
			s[R][j] = s[R][j - 1] + (jmp[R][j - 1] == -1 ? 0 : s[jmp[R][j - 1]][j - 1]);
		}
		while (i < q && r[idr[i]] == R) {
			int L = l[idr[i]];
			int cnt = 1, cur = R;
			for (int j = 20 - 1; ~j; -- j) {
				if (jmp[cur][j] >= L) {
					cnt += 1 << j;
					cur = jmp[cur][j];
				}
			}
			mx[idr[i]] = cnt;
			++ i;
		}
	}
	i = 0;
	rep(R, n) {
		while (i < q && r[idr[i]] == R) {
			int L = l[idr[i]];
			ll &S = sum[idr[i]];
			int cur = R;
			for (int j = 20 - 1; ~j; -- j) {
				if (jmp[cur][j] >= L) {
					S += s[cur][j];
					cur = jmp[cur][j];
				}
			}
			S += cur + 1;
			S -= 1LL * mx[idr[i]] * L;
			++ i;
		}
	}
	i = 0;
	for (int L = n - 1; ~L; -- L) {
		jmp[L][0] = lower_bound(x, x + n, x[L] + K) - x;
		s[L][0] = L - 1;
		for (int j = 1; j < 20; ++ j) {
			jmp[L][j] = jmp[L][j - 1] == n ? n : jmp[jmp[L][j - 1]][j - 1];
			s[L][j] = s[L][j - 1] + (jmp[L][j - 1] == n ? 0 : s[jmp[L][j - 1]][j - 1]);
		}
		while (i < q && l[idl[i]] == L) {
			int R = r[idl[i]];
			ll &S = sum[idl[i]];
			int cur = L;
			for (int j = 20 - 1; ~j; -- j) {
				if (jmp[cur][j] <= R) {
					S -= s[cur][j];
					cur = jmp[cur][j];
				}
			}
			S -= cur - 1;
			S += 1LL * mx[idl[i]] * R;
			++ i;
		}
	}
	rep(i, q) {
		ll ans = sum[i] - (r[i] - l[i] + 1) - 1LL * (mx[i] - 1) * (r[i] - l[i] + 1);
		printf("%lld\n", ans);
	}
	return 0;
}