#P5323. [BJOI2019] 光线

[BJOI2019] 光线

Description

When a beam of light hits a layer of glass, a certain proportion of the light will pass through the glass, a certain proportion will be reflected back, and the rest will be absorbed by the glass.

Suppose for any xx, x×ai%x \times a_i\% units of light will pass through it, and x×bi%x \times b_i\% will be reflected back. Now there are nn layers of glass stacked together. If 11 unit of light hits the 11st layer of glass, how many units of light can pass through all nn layers of glass?

Input Format

The first line contains a positive integer nn, representing the number of glass layers.
The next nn lines each contain two non-negative integers ai,bia_i, b_i, representing the transmittance and reflectance of the ii-th layer.

Output Format

Output one line containing one integer, representing the amount of light that passes through all the glass layers modulo 109+710^9 + 7.
It can be proven that the answer must be a rational number. Let the answer be a/ba/b (where aa and bb are coprime positive integers). If the value you output is xx, you need to ensure that abx (mod 109+7)a \equiv bx \space (\text{mod }10^9 + 7).

2
50 20
80 5
858585865
3
1 2
3 4
5 6
843334849

Hint

Explanation for Sample 1:

As shown in the figure, the light ray enters from the upper-left corner. There are 0.50.5 units of light passing through the 11st layer of glass, and 0.20.2 units of light being reflected back. Of these 0.50.5 units of light, 0.40.4 units pass through the 22nd layer of glass, and 0.0250.025 units of light are reflected back. Of these 0.0250.025 units of light, 0.01250.0125 units pass through the 11st layer of glass, and 0.0050.005 units of light are reflected back. Of these 0.0050.005 units of light, 0.0040.004 units pass through the 22nd layer of glass... Therefore, the total amount of light passing through the two layers of glass is 0.40404...=40/990.40404... = 40/99 units. Modulo 109+710^9+7, this equals 858585865858585865.

Constraints:
For 5%5\% of the testdata, n=1n=1;
For 20%20\% of the testdata, n2n \le 2;
For 30%30\% of the testdata, n3n \le 3;
For 50%50\% of the testdata, n100n \le 100;
For 70%70\% of the testdata, n3000n \le 3000;
For 100%100\% of the testdata, n5×105n \le 5\times 10^5, 1ai1001 \le a_i \le 100, 0bi990 \le b_i \le 99, 1ai+bi1001 \le a_i+b_i \le 100.

In each group, aia_i and bib_i are generated randomly among integers that satisfy the above constraints.

Translated by ChatGPT 5