SAlt

Time limit: 1.5s Memory limit: 256MB Input: Output:

Mathematical Final Boss is getting tired from all his success and decided to start playing with some integer sequences.

After a while, he found a very interesting function which he called SAltSAlt. For a sequence of numbers S=a1,a2,,akS = a_1, a_2, \ldots, a_k, he takes the non-increasing sorted sequence and stars to alternatively add and substract numbers.
Formally if the sorted sequence is ai1,ai2,,aika_{i_1},a_{i_2},\ldots, a_{i_k}, we have
SAlt(S)=p=1k(1)(p1)aipSAlt(S) = \sum_{p=1}^{k}(-1)^{(p-1)}\cdot a_{i_p}.

This is too easy for our Final Boss, so, for a sequence of numbers he now wants to compute the sum of the SAltSAlt values for all its subsets.

Now every morning he takes an integer sequence AA with NN numbers and QQ queries qi=(li,ri)q_i=(l_i,r_i) that ask for the SAltSAlt sum of all subsets of numbers of the substring A[li,ri]A[l_i,r_i].

He can do all these computations in less than a second and he is now curious if you can do it too with the help of a modern computer.

Because the numbers can become very large, you have to compute it modulo 109+710^9 + 7.

Input data

First line will contain one integer NN, 1N1051 \leq N \leq 10^5 - the length of the sequence.
The second line will contain NN numbers (1Ai2105)(1 \leq A_i \leq 2\cdot 10^5) - the elements of the sequence.
The third line contains QQ, 1Q1051 \leq Q \leq 10^5 - the number of queries.
The following QQ lines each have a pair of numbers li,ril_i,r_i denoting the query interval.

Output data

The ii-th line will represent the answer to the ii-th query given by the Final Boss.

Constraints and clarifications

  • For 2020 points, it is guaranteed that N20N\leq20 and Q50Q\leq 50.
  • For the other 8080 points, we have N105N \leq 10^5 and Q105Q \leq 10^5.

Example

stdin

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

stdout

8
80
4

Explanation

For the first query, we have the substring 4,34,3, with the subsets S1={4},S2={3},S3={3,4}S_1 = \{4\}, S_2 = \{3\}, S_3 = \{3,4\}.
We have SAlt(S1)=4SAlt(S_1) = 4, SAlt(S2)=3SAlt(S_2) = 3 and SAlt(S3)=43=1SAlt(S_3) = 4 - 3 = 1.
The answer for this query is 4+3+1=84+3+1=8.

Log in or sign up to be able to send submissions!