Monster Killer
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Walk Alone is playing a game recently. In this game, there are n monsters numbered from 1 to n, the i-th of which has an attack ability of a_i. Walk Alone is required to kill all of them in order.

To kill a monster, he needs to battle with it. He can battle with the -th monster if and only if all monsters from 1 to i are killed.

Initially, Walk Alone's attack ability m equals to 0. After a battle with the i-th monster, three situations may happen:
  • , he kills the monster.
  • , he kills the monster, but his attack ability m may become m - 1 with a probability of p_i.
  • , he loses the battle. The monster is still alive, but his attack ability m may become with a probability of p_i.

When he loses a battle, he will keep trying until he wins.

Now Walk Alone wants to know the \textbf{expected number of battles} he needs to go through in total.

It can be shown that the answer can always be expressed as an irreducible fraction , where x and y are integers and . Output such an integer a that and .

输入描述:

The first line contains an integer , the number of monsters.

The i-th of the next n lines contains two integers and , and .

输出描述:

Output a single number, the expected number of battles modulo .
示例1

输入

复制
3
1 100
0 50
1 100

输出

复制
499122181

说明

In the first example, the result of each battle is as below:
  - Battle 1: monster 1 is still alive, and his attack ability become 1.
  - Battle 2: monster 1 is killed, and his attack ability remains 1.
  - Battle 3: monster 2 is killed, and with 50\% probability his attack ability become 0.
  - If his attack ability is 0:
    - Battle 4: monster 3 is still alive, and his attack ability become 1.
    - Battle 5: monster 3 is killed.
  - If his attack ability is 1, monster 3 is killed in battle 4.

The expected number of battles is 4.5, which is congruent to 499\,122\,181 modulo 998\,244\,353.
示例2

输入

复制
5
2 50
6 30
1 20
5 50
4 40

输出

复制
332748140