Limits 2.5s, 512 MB

You are given NN integer numbers (A1,A2,A3AN)(A_1, A_2, A_3 … A_N). You will also be given some query. Each query will be of the format (L,R)(L, R). For each query you need to find all the sequence such that Lv1<v2<v3<vkRL \le v_1 < v_2 < v_3 … < v_k \le R, and (Av1+Av2+Av3++Avk)(Av_1 + Av_2 + Av_3 + … + Av_k) is divisible by MM. You need to find out the sum of product of all the numbers in all such sequences. Basically SUM of all possible(Av1Av2Av3Avk)\text{SUM of all possible}(Av_1 * Av_2 * Av_3 * … * Av_k).

Input

The first line contains three integers NN, QQ, MM (1N,Q300000,1M301 \le N, Q \le 300000, 1 \le M \le 30). The following line contains NN integers A1A_1, A2A_2, A3A_3, …, ANA_N (0Ai<10000000000 \le A_i < 1000000000). The next QQ lines each contain two integers LL, RR (1LRN1 \le L \le R \le N).

Output

Print QQ lines, each line must contain the result of the query modulo 1000000007

Sample

InputOutput
5 2 2
1 2 3 4 5
1 5
2 4
359
14

Submit

Login to submit.

Statistics

65% Solution Ratio
ZeronfinityEarliest, Jun '18
Kuddus.6068Fastest, 0.5s
solaimanopeLightest, 83 MB
fahimcp495Shortest, 1918B
Toph uses cookies. By continuing you agree to our Cookie Policy.