Universal Cup Judging System

Universal Cup

시간 제한: 3.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓
통계

Description

There is a square grid with $N \times N$ cells. We denote the cell in the $i$-th row from the top and the $j$-th column from the left as $(i, j)$. Each cell $(i, j)$ has an integer $A_{i,j}$ written on it, satisfying $1 \le A_{i,j} \le (N - K)^2$. You are going to perform the following operations in order:

  • Choose $K$ out of the $N$ rows and remove the cells in the chosen rows.
  • Choose $K$ out of the $N$ columns and remove the cells in the chosen columns.

Depending on how the rows and columns are chosen, the integers written on the remaining $(N - K)^2$ cells may be pairwise distinct. Find the number of ways to choose the rows and columns to remove such that this condition is satisfied, modulo $998244353$.

Two ways of choosing are considered different if and only if there is at least one row or column that is chosen in one way and not chosen in the other.

Input

The input is given from Standard Input in the following format:

N K
A_{1,1} A_{1,2} ... A_{1,N}
:
A_{N,1} A_{N,2} ... A_{N,N}

Constraints

  • $1 \le K < N \le 1000$
  • $1 \le K \le 5$
  • $1 \le A_{i,j} \le (N - K)^2$ ($1 \le i \le N, 1 \le j \le N$)
  • All input values are integers.

Output

Print the number of ways to choose the rows and columns satisfying the condition, modulo $998244353$.

Examples

input1

3 1
3 1 4
1 4 2
2 3 1

output1

6

input2

3 2
1 1 1
1 1 1
1 1 1

output2

9

input3

6 3
1 7 2 5 6 8
8 9 1 7 5 9
5 2 3 6 4 1
1 2 6 3 9 2
2 4 3 1 5 4
6 9 5 4 2 2

output3

10

Note

Sample 1 Explanation

In the following $6$ ways of choosing, the remaining $(N - K)^2$ cells contain the integers $1, 2, 3, 4$ once each, so they satisfy the condition:

  • Remove the $1$-st row from the top and the $1$-st column from the left
  • Remove the $1$-st row from the top and the $2$-nd column from the left
  • Remove the $1$-st row from the top and the $3$-rd column from the left
  • Remove the $2$-nd row from the top and the $3$-rd column from the left
  • Remove the $3$-rd row from the top and the $2$-nd column from the left
  • Remove the $3$-rd row from the top and the $3$-rd column from the left

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1494EditorialOpen题解jianglyView
#1346EditorialOpen题解MilmonView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.