P15864 T671115 [LBA-OI R3 D] Array Chess
Background
To win the LBA Grand Finals, the coach is designing a brand-new offensive formation.
Description
We are given a basketball court with $n$ horizontal division lines and $m$ vertical division lines, dividing the court into an $n \times m$ grid of regions.
The coach assigns a **unique** formation number (from $0$ to $nm-1$) to each region, forming a formation matrix.
The **formation diversity value** of a matrix is defined as the number of **distinct values** of the minimum missing formation number across all submatrices of the matrix.
::::info[Example]{open}
If the formation numbers in a submatrix are $\{0,1,3,4\}$, the minimum missing number is $2$.
If the formation numbers in a submatrix are $\{0,2\}$, the minimum missing number is $1$.
::::
Find the sum of the **formation diversity values** over all possible formation matrices.
Since the answer can be large, output it modulo $998244353$.
---
### Formal Statement
Given $n, m$.
An $n \times m$ matrix is valid if it is a permutation of integers from $0$ to $nm-1$.
Define $val$ of a matrix as the **size** of the set containing the $\text{mex}$ of all its submatrices.
Compute the sum of $val$ over all valid matrices, modulo $998244353$.
::::success[Definition of Submatrix]
A submatrix is formed by deleting a prefix of rows/columns and a suffix of rows/columns from the original matrix.
::::
Input Format
One line with two integers $n, m$.
Output Format
One integer representing the answer modulo $998244353$.
Explanation/Hint
### Explanation of Sample 1
There are two valid matrices:
1. `0 1`
2. `1 0`
For `0 1`, the submatrices are `0` (mex = $1$), `1` (mex = $0$), `0 1` (mex = $2$). The set is $\{0,1,2\}$, so $val = 3$.
The case `1 0` is symmetric.
Total answer: $3 + 3 = 6$.
### Data Constraints
| Subtask | $n \times m$ | Special Property | Score |
|:-:|:-:|:-:|:-:|
| $1$ | $\le 8$ | A | $10$ |
| $2$ | $\le 5 \times 10^6$ | A | $10$ |
| $3$ | $\le 225$ | B | $10$ |
| $4$ | $\le 6400$ | C | $20$ |
| $5$ | $\le 1.6 \times 10^5$ | D | $10$ |
| $6$ | $\le 5 \times 10^5$ | None | $20$ |
| $7$ | $\le 5 \times 10^6$ | None | $20$ |
Special Property A: $n = 1$.
Special Property B: $n, m \le 15$.
Special Property C: $n, m \le 80$.
Special Property D: $n, m \le 400$.
For $100\%$ data: $1 \le n \times m \le 5 \times 10^6$.
**Please pay attention to the constant complexity of your implementation.**