QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#11660. Strong-box

统计

ByteGuy owns a strong-box protected with a lock. This lock has $n$ knobs. Each knob can be situated in one of $p$ possible positions.

ByteGuy has not used his strong-box for a long time now, so he has forgotten the configuration of knobs which opens the strong-box. He went to the company producing locks, where he learned about construction of the lock. It consists of $n$ knobs and the same number of bolts. All of them (both bolts and knobs) can be in one of $p$ allowed positions numbered from $0$ to $p - 1$. The lock opens, when all of the bolts are set to the position $0$. Turning $i$-th knob by one position (from position $0$ to $1$, from $1$ to $2$, ..., from $p - 2$ to $p - 1$, from $p - 1$ to $0$) causes, that $j$-th bolt rotates by $c_{i,j}$ positions (from position $l$ to $(l + c_{i,j}) \bmod p$). The manufacturer of locks helped ByteGuy and gave him a modern 3D-scaner, which allowed to check the configuration of the bolts hidden inside a strong-box.

Locks manufactured for strong-boxes are of high quality and there is only one configuration of knobs which opens the lock.

Task

Write a program, which:

  • reads the description of a lock in ByteGuys's strong-box,
  • computes the configuration of knobs which opens the lock,
  • writes the result to the standard output.

Input

The first line contains two integers $n$ - the number of knobs, $1 \le n \le 300$ and the prime number $p$ - the number of possible positions of knobs, $3 \le p \le 40\,000$. The following line contains $n$ integers in the range $0 \ldots p - 1$ - positions, in which successive knobs are located. The third line contains $n$ integers from the range $0 \ldots p - 1$ - positions of consecutive bolts of ByteGuy's strong-box. Following $n$ lines contain descriptions of consecutive knobs - $i$-th of these lines contains exactly $n$ integers - $c_{i,0}$, $c_{i,1}$, $\ldots$, $c_{i,n-1}$, $0 \le c_{i,j} < p$.

Output

The only line of output should contain $n$ integers from the range $0 \ldots p - 1$, separated with single spaces - the configuration of knobs which opens the lock.

Example

Input

2 3
1 1
2 2
1 0
0 1

Output

2 2

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.