AT_scpc2026_div1_g 오fill
Description
#### 表示言語
/ / Cenix wants to fill an $ N \times M $ grid using the following six types of square tiles. There are plenty of each type of tile, and they can be rotated before placement. When placing tiles, every edge connected to a path must touch an edge connected to a path on a neighboring tile. However, not all paths need to be connected.

While filling the grid, Cenix realized that the task was too easy. Cenix now intends to fill the remaining cells using only tiles that connect one side and tiles that connect three sides.

A grid with some cells already filled with tiles is given as follows.
- The type of tile placed in the $ i $ -th row and $ j $ -th column of the grid is denoted by $ A_{i,j} $ .
- If no tile is placed in that cell, $ A_{i,j} $ is $ -1 $ .
- If a tile is placed in that cell, $ A_{i,j} $ is the sum of $ 1 $ (if the tile is connected to the top edge), $ 2 $ (if connected to the bottom edge), $ 4 $ (if connected to the left edge), and $ 8 $ (if connected to the right edge).
Find the number of ways to fill the remaining cells using only these two types of tiles.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ M $ $ A_{1,1} $ $ A_{1,2} $ $ \dots $ $ A_{1,M} $ $ A_{2,1} $ $ A_{2,2} $ $ \dots $ $ A_{2,M} $ $ \vdots $ $ A_{N,1} $ $ A_{N,2} $ $ \dots $ $ A_{N,M} $
Output Format
Output the number of ways to fill the grid, modulo $ 998\,244\,353 $ .
Explanation/Hint
### Sample Explanation 1

### Constraints
- $ 1 \le N, M \le 500\,000 $
- $ 1 \le NM \le 500\,000 $
- $ -1 \le A_{i,j} \le 15 $
- All input values are integers.