You are given a 0-indexed array of integers. We define as the operation that takes all elements in the range and flips their sign, i.e. positive becomes negative, negative becomes positive.
You are given queries of the form . For each query, determine the number of ways to achieve the minimum possible product in the subarray using at most operations in total, each applied to an arbitrary subarray of . Since the number of ways can be quite large, print it modulo .
A way is a sequence of at most operations. Two ways are considered different if they contain a different number of operations or if their operations differ at any position in the sequence. Thus, the order of operations matters, the same subarray may be flipped multiple times, and the empty sequence (performing no operations) is also a valid way.
Input data
The first line of standard input contains two space-separated integers and , representing the size of the array and the number of queries.
The second line of standard input contains space-separated integers , representing the elements of the array .
The next lines of standard input each contain three space-separated integers , and , representing the -th query.
Output data
Each line of the next lines of standard output will contain the answer to the -th query, modulo .
Constraints and clarifications
- .
- .
- , for all .
- , for all .
- , for all .
| # | Score | Constraints |
|---|---|---|
| 0 | 0 | Examples. |
| 1 | 10 | , , , $ |
| 2 | 10 | , , . |
| 3 | 15 | , , . |
| 4 | 15 | , , , all queried subarrays contain no zeroes. |
| 5 | 15 | , , , all queried subarrays contain at least one zero. |
| 6 | 15 | , , . |
| 7 | 20 | No additional restrictions. |
Example
stdin
7 7
1 6 -1 4 -5 0 7
1 4 4
2 3 1
2 3 2
0 4 3
2 2 1
1 3 0
5 6 2
stdout
5550
2
7
1818
1
1
13
Explanation
In the second query, the minimum possible product is , and it can be achieved by the following sequences of operations:
- ;
- .
In the third query, the minimum possible product is , and it can be achieved by the following sequences of operations:
- ;
- ;
- , ;
- , ;
- , ;
- , ;
- , .
In the fifth query, the minimum possible product is , and it can be achieved by the following sequences of operations:
- .
In the sixth query, the minimum possible product is , and it can be achieved by the following sequences of operations:
- .
In the seventh query, the minimum possible product is , and it can be achieved by the following sequences of operations:
- ;
- ;
- ;
- ;
- , ;
- , ;
- , ;
- , ;
- , ;
- , ;
- , ;
- , ;
- , .
Example
stdin
3 2
3 -2 -5
0 2 0
1 2 1
stdout
1
2
Explanation
In the first query of the second example, no operations are allowed, so the product stays . This is the minimum possible product, and it is achieved by exactly one sequence of operations, the empty one, so the answer is :
- .
In the second query of the second example, the minimum possible product is , and it can be achieved by the following sequences of operations:
- ;
- .