ADATAXES - Ada and Taxes

no tags 

As you might already know, Ada the Ladybug is a farmer. She grows vegetables in a long furrow. All of the vegetables have some height. Local politicians tax small vegetables, but as the furrow is very long, they always tax just a part of it.

The taxes always have some limit on height. They are calculated very simply: Tax collectors multiply the heights of all vegetables, which are lesser or equal to limit and are on desired segment.

The taxes might be very high so tax collectors just round their income and take only 1000000007 (109+7) banknotes. They are very kind, so they always leave the rest to Ada. She is interested in how much they will leave her.

NOTE: If none of the vegeteble is lesser/equal to given limit, Ada is left with symbolical 1 "money".


The first line contains an integer 1 ≤ N, Q ≤ 3*105, the number of vegetables Ada grows and the number of times the tax collectors come.

The second line contains N integers 1 ≤ Ai ≤ 3*105, the heights of vegetables.

The next Q lines contains three integers 0 ≤ L ≤ R < N, the left and right vegetables of segment and 1≤ H ≤ 3*105, the limit.


Print a single line for each query with the number of money Ada will be left with after each tax collecting.

Example Input

10 6
1 2 3 4 5 10 9 8 7 6
5 5 5
0 2 3
0 9 9
4 8 8
2 4 11
2 2 3

Example Output


hide comments
yogahmad: 2017-07-21 11:14:22

Last edit: 2017-07-21 11:45:16
morass: 2017-06-29 14:38:03

@[Rampage] Blue.Mary: Sorry, seems I deleted part of input instead of harsh warning :'( is it better now? :O

[Rampage] Blue.Mary: 2017-06-29 12:20:14

The input specification doesn't match the sample input.

Added by:morass
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)