QOJ.ac

QOJ

时间限制: 6 s 内存限制: 256 MB 总分: 100

#4267. ydc's Bonus

统计

One day, while browsing the internet, ydc discovered a competition. There are $n$ participants in this competition, numbered $1, \dots, n$, and ydc's number is $n$.

If you manage to achieve $i$-th place in this competition, you will receive $p_i$ units of currency as a prize. Since there is prize money to be won, ydc naturally does not want to miss out on this opportunity, and naturally, the more currency, the better. Therefore, ydc conducted thorough research and calculated the probability distribution of the scores for all participants (including himself).

The scores in this competition can be any real number in $[0, 1]$. For the $i$-th person, the probability of scoring $x$ is proportional to a polynomial function $f_i(x)$. Of course, the domain of $f_i(x)$ is $[0, 1]$.

If the $i$-th person's function is $f_i(x)=2$, then the probability of them obtaining any score is equal; if a person's function is $f_i(x)=x+1$, then the probability of them scoring $0$ is half the probability of them scoring $1$.

You need to calculate the expected value of the prize money ydc receives. Since the scores are real numbers, the probability of two people having the same score is infinitesimal, so there is no need to consider ties in ranking.

ydc has, of course, already calculated it! But he wants to test you.

A rational number can always be represented in the form $\frac{a}{b}$, where $a \geq 0, b > 0$, and $a, b$ are coprime. For a prime $p$, if $b$ is not a multiple of $p$, we can define $\frac{a}{b} \bmod p$ as the smallest non-negative integer $x$ such that $bx \equiv a \pmod{p}$. If $b$ is a multiple of $p$, then $\frac{a}{b} \bmod p$ is undefined.

The answer is guaranteed to be a rational number; output the result modulo $998244353$ ($7 \times 17 \times 2^{23} + 1$, a prime number) (it is guaranteed to be defined).

Input

The first line contains an integer $n$.

The second line contains $n$ integers, where the $i$-th number represents $p_i$. It is guaranteed that $p_1 \geq p_2 \geq \dots \geq p_n$.

The next $n$ lines each start with a positive integer $t_i$, representing that the function for the $i$-th person is a polynomial of degree $t_i - 1$ defined on $[0, 1]$. This is followed by $t_i$ non-negative integers, where the $j$-th number represents the coefficient of the $x^{j-1}$ term in the function. All coefficients are less than $998244353$.

Obviously, all functions are greater than or equal to $0$ within the range $[0, 1]$. It is guaranteed that the area under the curve of all functions within the range $[0, 1]$ is defined and non-zero modulo $998244353$.

Output

Output a single integer representing the expected amount of currency ydc receives, modulo $998244353$.

Examples

Input 1

2
2 1
1 1
2 0 1

Output 1

665496237

Constraints

Test Case ID $n$ $\sum_{i = 1}^{n} t_i$ Special Constraints
1 $=2$ $= 5$ None
2 $=10$ None
3 $=10$ $= 40$ None
4 $= 60$ None
5 $= 80$ None
6 $= 100$ None
7 $=100$ $= 400$ None
8 $= 600$ None
9 $= 800$ None
10 $= 1000$ None
11 $=500$ $= 4000$ All prizes are equal
12 $= 4000$ All functions are identical
13 $= 4000$ All prizes except 1st and last are equal
14 $= 4000$ All prizes except 1st and last are equal
15 $= 1500$ None
16 $= 2000$ None
17 $= 2500$ None
18 $= 3000$ None
19 $= 3500$ None
20 $= 4000$ None

The data is guaranteed to be generated uniformly at random.

For $1 \leq i \leq n$, $0 \leq p_i \leq 10000$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.