Flip
Time limit10sMemory limit512 MB
Given sets of people numbered 1 to 2n, find for each set the probability that all its members land on the same team under the coin-flip assignment, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Combinatorics, Math, Prefix sum
- Solved
- No attempts yet
Problem
Assume people numbered from to are assigned to two teams of size using the following procedure. Find, for each given set , the probability that all people in that set end up on the same team. Display it modulo 998 244 353.
- In order from to , each person flips a fair coin.
- If the coin lands heads up, the person joins the first team, unless that team already has people. In that case, the person joins the second team.
- If the coin lands tails up, the person joins the second team, unless that team already has people. In that case, the person joins the first team.
Input
The first line contains two integers and (; ).
The -th of the next lines describes set . It contains an integer (), followed by integers ().
The sum of all does not exceed .
Output
For each from to , display the probability that all people from the set end up on the same team.
It can be shown that any such probability can be written as an irreducible fraction with . Then there is a unique integer with and . Display this .
Hint
In the first test case, people and (and people and ) end up on the same team with probability . For any other pair, the probability is .