CF2006F Dora's Paint
Description
Input Format
Output Format
Explanation/Hint
It can be proved that this is the only way to paint the matrix in $ 3 $ steps. So the beauty of the matrix $ \\left\[\\begin{matrix}2&1\\\\2&2\\end{matrix}\\right\] $ is $ 1 $ . Similarly, if any other element of the matrix is changed, the beauty is always $ 1 $ , so the expected beauty of the real matrix $ b $ is $ 1 $ .
In the second test case, the matrix $ a = \\left\[\\begin{matrix}1&2\\\\2&2\\end{matrix}\\right\] $ . Let's consider changing the element $ (2, 2) $ to calculate the answer.
It can be proven that it's impossible to paint the initial matrix into $ \\left\[\\begin{matrix}1&2\\\\2&1\\end{matrix}\\right\] $ , so its beauty is $ 0 $ . If any other element of the matrix is changed, the beauty is always $ 2 $ , so the expected beauty is $ \\frac{0 + 2 + 2 + 2}{4} = \\frac{6}{4} \\equiv 499\\,122\\,178 \\pmod {998\\,244\\,353}$$$.