AT_past20_k 良いグリッド

Description

Consider a $ 4\times 4 $ grid with a number written on each cell. Let $ (i,j) $ be the cell in the $ i $ -th row from the top and $ j $ -th column from the left, and $ a_{i,j} $ be the number written on it. We say this grid is **good** if both of the following conditions are met: - The numbers written on each row increase strictly monotonically from left to right. That is, $ a_{i,j} < a_{i,j+1} $ for all $ i,j\ (1\leq i\leq N, 1\leq j< N) $ . - The numbers written on each column increase strictly monotonically from top to bottom. That is, $ a_{i,j} < a_{i+1,j} $ for all $ i,j\ (1\leq i< N, 1\leq j\leq N) $ . You are given an integer $ A_{i,j} $ for each $ 1\leq i,j\leq 4 $ . Find the number, modulo $ 998244353 $ , of good grids such that: - an integer between $ 1 $ and $ M $ , inclusive, is written on each cell, and - for $ 1\leq i,j\leq 4 $ , if $ A_{i,j}\neq -1 $ , then $ A_{i,j} $ is written on cell $ (i,j) $ .

Input Format

The input is given from Standard Input in the following format: > $ M $ $ A_{1,1} $ $ A_{1,2} $ $ A_{1,3} $ $ A_{1,4} $ $ A_{2,1} $ $ A_{2,2} $ $ A_{2,3} $ $ A_{2,4} $ $ A_{3,1} $ $ A_{3,2} $ $ A_{3,3} $ $ A_{3,4} $ $ A_{4,1} $ $ A_{4,2} $ $ A_{4,3} $ $ A_{4,4} $

Output Format

Print the number, modulo $ 998244353 $ , of good grids that satisfy the conditions.

Explanation/Hint

### Sample Explanation 1 Two grids satisfy the conditions: ``` 1 2 3 4 2 3 4 5 3 4 5 7 4 5 8 9 ``` ``` 1 2 3 4 2 3 4 5 3 4 6 7 4 5 8 9 ``` ### Sample Explanation 3 Be sure to find the count modulo $ 998244353 $ . ### Constraints - $ 1\leq M \leq 30 $ - $ A_{i,j}=-1 $ or $ 1\leq A_{i,j}\leq M $ . - All input values are integers.