Upcoming Test

0

0 votes
Medium-Hard
Problem

Gokku and Tiwari have a test tomorrow. Tiwari found out that problemset has n questions and score of problems are stored in a array X, every question has score10. A test can't have totalscore>100 so only a subarray of the array X would be taken as the question of the test.

Tiwari also found a list which has q pair of integers l and r each pair suggested a subarray from lth element of array to rth element of array which could be given as question in the test .

Now, Tiwari wants to know in how many ways he can get more marks than Gokku for the given l and r.

As the number can be large, you need to output the number of ways % 1000000007.

Note:- Please read the sample explanation for better understanding.

Input

First line contain a single integer n as specified in problem statement.

Second line contains n space separated integers elements of array X

Third line contains a single integer q as specified in problem statement

Next q lines contain a pair of space separated integers l and r

Output

Print number of ways in which Tiwari gets more marks than Gokku for each query in new line.

Constraints

1n1000000

1l,r1000000

X[l]+X[l+1]+......+X[r]100

q200

Sample Input
5
1 1 2 2 1
2
1 2
2 3
Sample Output
5
13
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

For the 1st query, Phunsuk and Dungen both can get 0 or 1 in 1st question and 0 or 1 in 2nd question.

All possible cases include-:

Tiwari gets (0,1) and Gokku gets (0,0)

Tiwari gets (1,0) and Gokku gets (0,0)

Tiwari gets (1,1) and Gokku gets (0,0)

Tiwari gets (1,1) and Gokku gets (1,0)

Tiwari gets (1,1) and Gokku gets (0,1)

Editor Image

?