AT_abc411_e [ABC411E] E [max]
Description
There are $ N $ six-sided dice. The dice are numbered from $ 1 $ to $ N $ , and the numbers written on the faces of die $ i $ are $ A_{i,1},A_{i,2},\dots,A_{i,6} $ .
Now, all $ N $ dice will be rolled simultaneously. Find the expected value, modulo $ 998244353 $ , of the maximum value among the numbers written on the face that comes up on each die.
For any die, the face that comes up when the die is rolled is chosen independently and uniformly at random.
Finding the expected value modulo $ 998244353 $ It can be proved that the expected value to be found is always a rational number. Also, under the constraints of this problem, it can be proved that when the value is expressed as an irreducible fraction $ \frac{P}{Q} $ , we have $ Q \not\equiv 0 \pmod{998244353} $ . Therefore, there exists a unique integer $ R $ such that $ R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353 $ . Find this $ R $ .
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ A_{1,1} $ $ A_{1,2} $ $ \dots $ $ A_{1,6} $ $ A_{2,1} $ $ A_{2,2} $ $ \dots $ $ A_{2,6} $ $ \vdots $ $ A_{N,1} $ $ A_{N,2} $ $ \dots $ $ A_{N,6} $
Output Format
Output the answer.
Explanation/Hint
### Sample Explanation 1
Let $ x_i $ be the number written on the face that comes up on die $ i $ .
- Case $ x_1=1,x_2=1 $ : Occurs with probability $ \frac{2}{6}\times\frac{3}{6}=\frac{1}{6} $ , and the maximum value among the numbers written on the faces that come up is $ 1 $ .
- Case $ x_1=1,x_2=3 $ : Occurs with probability $ \frac{2}{6}\times\frac{3}{6}=\frac{1}{6} $ , and the maximum value among the numbers written on the faces that come up is $ 3 $ .
- Case $ x_1=4,x_2=1 $ : Occurs with probability $ \frac{4}{6}\times\frac{3}{6}=\frac{1}{3} $ , and the maximum value among the numbers written on the faces that come up is $ 4 $ .
- Case $ x_1=4,x_2=3 $ : Occurs with probability $ \frac{4}{6}\times\frac{3}{6}=\frac{1}{3} $ , and the maximum value among the numbers written on the faces that come up is $ 4 $ .
Thus, the expected value to be found is $ \frac{1}{6}\times 1 + \frac{1}{6}\times 3 + \frac{1}{3}\times 4 + \frac{1}{3}\times 4 = \frac{10}{3} \equiv 332748121 \pmod{998244353} $ .
### Sample Explanation 2
The numbers written on the faces that come up on dice $ 1,2 $ are always $ 1,2 $ , respectively, and their maximum value is always $ 2 $ .
### Constraints
- $ 1\leq N \leq 10^5 $
- $ 1\leq A_{i,j} \leq 10^9 $
- All input values are integers.