#P9869. F. Product of Sorting Powers

F. Product of Sorting Powers

F. Product of Sorting Powers

Problem Description

Given a sequence AA of length nn. There are mm queries, each given l,rl, r, let B1,B2,,Brl+1B_1, B_2, \dots, B_{r - l + 1} as the result of sorting Al,Al+1,,ArA_l, A_{l + 1}, \dots, A_r, calculate:

$$\left(\prod_{i = 1} ^ {r - l} {B_i} ^ {B_{i + 1}} \right) \bmod {(10 ^ 9 + 7)} $$

Input

The first line of the input contains two integers n,mn, m (1n1061 \le n \le 10 ^ 6, 1m50001 \le m \le 5000) - the length of AA and the number of queries. The second line contains nn integers A1,A2,,AnA_1, A_2, \dots, A_n (1Ai1091 \le A_i \le 10^9). Each of the following mm lines contains two integers l,rl, r (1lrn1 \le l \le r \le n).

Output

For each query, print a single integer - the answer of the query, modulo 109+710 ^ 9 + 7.

Sample Input

6 5
8 2 5 9 7 7
1 4
2 6
1 3
3 6
2 5

Sample Output

588255953
426219106
12500000
575819351
16793812

Source

2023“钉耙编程”中国大学生算法设计超级联赛(7)