QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#7366. Game

Statistiques

It is 23:00, and you have finally finished all your deadlines. You decide to play a game to relax. You notice that the ranked ladder is about to reset, so you decide to quickly reach the "minimum guarantee" (a rank floor).

You currently have 0 stars, and you reach the minimum guarantee when you have $n$ stars. Each game won grants you one star, and each game lost deducts one star. Specifically, when you have 0 stars, no further stars are deducted.

For convenience, we simplify the game process: when you have $i$ stars, your probability of winning is $p_i$. You want to know the expected number of games required to reach the minimum guarantee. For special considerations, you only need to output the result modulo 998244353.

Input

The first line contains an integer $n$, representing the number of stars required for the minimum guarantee.

The next $n$ lines each contain two integers $x_i, y_i$ ($i = 0, 1, \dots, n - 1$), representing the probability $p_i = \frac{x_i}{y_i}$.

Output

Output a single integer representing the result modulo 998244353.

In other words, if the answer can be expressed as a rational number $\frac{p}{q}$, you need to output $d \in [0, 998244353)$ such that $dq \equiv p \pmod{998244353}$.

Examples

Input 1

2
1 2
1 2

Output 1

6

Constraints

  • For 30% of the data, $n \le 100$.
  • For another 30% of the data, $x_i = 1, y_i = 2$.
  • For all data, $1 \le n \le 10^6$, $1 \le x_i \le y_i < 998244353$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.