Given a positive integer kk, two arrays are called kk-similar if:

  • they are strictly increasing;
  • they have the same length;
  • all their elements are positive integers between 11 and kk (inclusive);
  • they differ in exactly one position.

You are given an integer kk, a strictly increasing array aa and qq queries. For each query, you are given two integers liril_i≤r_i. Your task is to find how many arrays bb exist, such that bb is kk-similar to array [ali,ali+1,ari][a_{l_i},a_{l_i+1}…,a_{r_i}].

Input

The first line contains three integers nn, qq and kk (1n,q1051≤n,q≤10^5, nk109n≤k≤10^9) — the length of array aa, the number of queries and number kk.

The second line contains nn integers a1,a2,,ana_1,a_2,…,a_n (1aik1≤a_i≤k). This array is strictly increasing — a1<a2<<ana_1<a_2<…<a_n.

Each of the following qq lines contains two integers lil_i, rir_i (1lirin1≤l_i≤r_i≤n).

Output

Print qq lines. The ii-th of them should contain the answer to the ii-th query.

Examples

input

1
2
3
4
4 2 5
1 2 4 5
2 3
3 4

output

1
2
4
3

input

1
2
3
4
5
6
7
6 5 10
2 4 6 7 8 9
1 4
1 2
3 5
1 6
5 5

output

1
2
3
4
5
8
9
7
6
9

Note

In the first example:

In the first query there are 44 arrays that are 55-similar to [2,4][2,4]: [1,4],[3,4],[2,3],[2,5][1,4],[3,4],[2,3],[2,5].

In the second query there are 33 arrays that are 55-similar to [4,5]:[1,5],[2,5],[3,5][4,5]: [1,5],[2,5],[3,5].

Idea

对于 al,al+1,,ara_{l},a_{l+1},\cdots,a_r,我们只考虑更换其中一个位置的值,使得原序列仍然保持严格递增的性质,就能得到 ksimilark-\text{similar} 的数组 bb

对于 l<i<rl<i<ra[i]a[i] 可更换为 ai1+1,,ai1,ai+1,,ai+11a_{i-1}+1,\cdots,a_{i}-1,a_{i}+1,\cdots,a_{i+1}-1,共 ai+1ai12a_{i+1}-a_{i-1}-2 种方案;累加得,i=l+1r1(ai+1ai12)=ar+ar1al1al2×(rl1)\sum\limits_{i=l+1}^{r-1}(a_{i+1}-a_{i-1}-2)=a_r+a_{r-1}-a_{l-1}-a_l-2\times(r-l-1)

对于 ala_l,需要在 1al+111\sim a_{l+1}-1 中挑一个数字,讨论 ala_l 是否为 11,得到的方案数都为 al+12a_{l+1}-2;对于 ara_r,需要在 ar1+1ka_{r-1}+1\sim k 中挑选一个数字,讨论 ara_r 是否为 kk,得到的方案数都为 kar11k-a_{r-1}-1

综上所述,总方案数为 ara[l]2×(rl)+k1a_r-a[l]-2\times(r-l)+k-1

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/******************************************************************
Copyright: 11D_Beyonder All Rights Reserved
Author: 11D_Beyonder
Problem ID: CF1485B
Date: 2021 Feb. 28th
Description: Math
*******************************************************************/
#include<iostream>
using namespace std;
const int N=100005;
int n,q,k;
int a[N];
int main(){
cin>>n>>q>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=q;i++){
int l,r;
cin>>l>>r;
cout<<a[r]-a[l]-2*(r-l)+k-1<<endl;
}
return 0;
}