cswork / OAOpen practice workspace

UberOA #61

Sum of Scores of Built Arrays

Estimated MediumJudge-ready

Topics (AI-labelled)Bits & MathPrefix & Ranges

For each position i, choose any prime from the closed interval [low[i],high[i]] to form an array. The score of an array is the product of all its elements. Find the sum of scores over all distinct valid arrays, modulo 10⁹+7. Each interval is guaranteed to contain at least one prime. The ranges and modulo rule truncated during import have been restored from the original statement.

This site has made the standard input and output explicit.

Input

The first line contains n, followed by n lines of low high; 1≤n≤100000, 1≤low≤high≤1000000, and each interval contains at least one prime.

Output

Output one integer, the answer.

Example 1

Input:

2
1 3
3 5

Output:

40

Example 2

Input:

3
2 2
2 2
2 2

Output:

8

Example 3

Input:

3
1 4
2 5
3 30

Output:

6350

Example notes

Example 1: (2+3)×(3+5)=40. Example 2: all three positions can only choose 2, giving a product of 8; the original second example [1,1] contains no prime, violating the guarantee, so it was changed to [2,2]. Example 3: the three prime sums are 5, 10 and 127, with product 6350; the original output 30 counted only one combination.

Editorial

Loading solution…