Roxy, the space traveler, is facing a very abstract problem. Since she's clueless as to how to solve it, you, as her best friend, have no choice but to help her out:
She is given an array consisting of integers, and pairs of endpoints , each representing the subarray , where .
Task
For each such pair , Roxy is asked what is the maximum number of disjoint sum- subarrays one can choose from the queried array . Two subarrays are considered disjoint if they have no entries in common; however, they can still have neighboring endpoints. Note that, there might be entries from the queried array that are not part of any of the chosen subarrays.
Input
The first line of the input contains a single integer .
The second line contains space-separated integers .
The third line contains the number of queries.
The next lines contain two numbers and each, representing the query.
Output
Print lines: on the line you should print the answer to the query.
Constraints
- for all
- for all
# | Points | Constrains |
---|---|---|
1 | 22 | |
2 | 39 | |
3 | 39 | No further constraints. |
Examples
stdin
10
1 2 -3 0 1 -4 3 2 -1 1
3
1 10
1 5
2 9
stdout
4
2
2