#P71. [CSP-S 2019 Day 2] Guest Treating

[CSP-S 2019 Day 2] Guest Treating

Person in Charge

Problem Description

Emiya is a high school student who is good at cooking. He has mastered nn kinds of cooking methods and can cook using mm kinds of main ingredients. For the sake of convenience, we number the cooking methods from 11 to nn and the main ingredients from 11 to mm.

Each dish Emiya makes uses exactly one cooking method and exactly one main ingredient. More specifically, Emiya can make ai,ja_{i,j} different dishes that use cooking method ii and main ingredient jj (1in1 \le i \le n, 1jm1 \le j \le m), which means Emiya can make a total of $\sum\limits_{i=1}^{n} \sum\limits_{j=1}^{m} a_{i,j}$ different dishes.

Today, Emiya is going to prepare a meal to entertain his good friends Yazid and Rin. However, the three of them have different requirements for the combination of dishes. More specifically, for a combination plan containing kk dishes:

  • Emiya will not let everyone go hungry, so he will make at least one dish, i.e., k1k \ge 1.
  • Rin wants to taste dishes made with different cooking methods, so she requires that each dish uses a distinct cooking method.
  • Yazid does not want to taste too many dishes made with the same ingredient, so he requires that each main ingredient is used in at most half of the dishes (i.e., k2\lfloor \frac{k}{2} \rfloor dishes).

Here, x\lfloor x \rfloor is the floor function, representing the largest integer not exceeding xx.

These requirements do not trouble Emiya, but he wants to know how many different combination plans meet all the requirements. Two plans are different if and only if there is at least one dish that appears in one plan but not in the other.

Emiya has come to you for help. Please calculate the number of valid combination plans modulo the prime number 998,244,353998,244,353 and tell him the result.

Input Format

The first line contains two integers nn and mm separated by a single space.

Lines 2 to n+1n + 1 each contain mm integers separated by a single space, where the mm numbers in line i+1i + 1 are ai,1,ai,2,,ai,ma_{i,1}, a_{i,2}, \cdots, a_{i,m} in sequence.

Output Format

Output a single integer on one line, representing the number of valid plans modulo 998,244,353998,244,353.

Samples

2 3 
1 0 1
0 1 1
3
3 3
1 2 3
4 5 0
6 0 0
190

Sample 1 Explanation

In this sample, for each pair (i,j)(i, j), Emiya can make at most one dish, so we directly describe a dish by giving the numbers of the cooking method and main ingredient.

The valid plans include:

  • Making one dish with cooking method 11 and main ingredient 11, and one dish with cooking method 22 and main ingredient 22.
  • Making one dish with cooking method 11 and main ingredient 11, and one dish with cooking method 22 and main ingredient 33.
  • Making one dish with cooking method 11 and main ingredient 33, and one dish with cooking method 22 and main ingredient 22.

Thus, the output result is 3mod998,244,353=33 \bmod 998,244,353 = 3. Note that all plans containing only one dish are invalid, because the only main ingredient is used in more than half of the dishes, which does not meet Yazid's requirement.

Sample 2 Explanation

Emiya must make at least 22 dishes.

The number of valid plans with 22 dishes is 100100.

The number of valid plans with 33 dishes is 9090.

Therefore, the total number of valid plans is 100+90=190100 + 90 = 190.

Sample 3

See meal/meal3.in and meal/meal3.ans in the contestant's directory.

Data Range

Test Case ID n=n= m=m= ai,j<a_{i,j}< Test Case ID n=n= m=m= ai,j<a_{i,j}<
11 22 22 22 77 1010 22 10310^3
22 33 88 33
33 55 22 9129\sim 12 4040 22
44 33 131613\sim 16 33
55 1010 22 172117\sim 21 500500
66 33 222522\sim 25 100100 2×1032\times 10^3 998,244,353998,244,353

For 100%100\% of the data: 1n1001 \le n \le 100, 1m20001 \le m \le 2000, 0ai,j<998,244,3530 \le a_{i,j} \lt 998,244,353.