LearnPy Hub
← Arena
AdvancedRating 1500

Range Products

Answer queries for the product of a[l..r] (1-based) modulo 1 000 000 007. No value is a multiple of the modulus, so use prefix products and modular inverses.

Input

n, the array, q, then q lines 'l r'.

Output

q lines.

Sample 1

Input
5
1 2 3 4 5
3
1 5
2 3
4 4
Output
120
6
4

Sample 2

Input
1
7
1
1 1
Output
7
solution.py
Output appears here
Range Products · Python Arena problem · LearnPy Hub