Ability

Compute the expected damage of one attack where abilities are tried in a uniformly random order without replacement until one fires, and output the fraction modulo 1e9+7.

Medium7ProbabilityMathCombinatoricsDynamic programmingNo attempts yetTime limit2sMemory limit512 MB

Problem

A player fights monsters in a web game and has all NN attack abilities equipped at once. The abilities are numbered 1 through NN.

Ability ii has a trigger probability pip_i and a damage value did_i. When the player issues a trigger command to ability ii, the ability fires with probability pip_i and deals did_i damage to the opponent, and with probability 1pi1 - p_i it does not fire and nothing happens.

One attack opportunity runs like this.

  1. Choose one of the equipped abilities. Every ability is equally likely to be chosen.
  2. Issue a trigger command to the chosen ability.
  3. If the ability fires, the attack opportunity is spent and the process ends.
  4. If it does not fire, choose one of the abilities that has not received a command yet, again with equal probability, then go back to step 2.
  5. If every ability has received a command and none of them fired, the attack opportunity is spent with no damage.

Given the trigger probability and the damage of all NN abilities, compute the expected damage dealt in one attack opportunity.

Input

The first line contains the number of abilities NN (1N50001 \le N \le 5000).

Line ii of the next NN lines contains two integers pip_i and did_i (1pi,di1091 \le p_i, d_i \le 10^9) separated by a space. Ability ii fires with probability pi/109p_i / 10^9 and deals did_i damage when it fires.

Output

Print the expected damage dealt in one attack opportunity. Write the expected value as an irreducible fraction a/ba/b and print (a×b1)mod(109+7)(a \times b^{-1}) \bmod (10^9 + 7) instead, where b1b^{-1} is the multiplicative inverse of bb modulo 109+710^9 + 7. This value exists for every input given in this problem.