Strong-box
Time limit1sMemory limit128 MB
Given the current knob and bolt positions and the coupling matrix modulo a prime, find the knob configuration that sets all bolts to zero.
- Level
Medium7 of 10
- Topics
- Math, Matrix, Number theory, Implementation
- Solved
- No attempts yet
Problem
ByteGuy owns a strong-box secured by a lock with knobs. Each knob, and each of the bolts hidden inside the lock, can be in one of positions numbered to , where is prime.
The lock opens exactly when every bolt is at position .
Turning knob forward by one position (from to , from to , ..., and from back to ) rotates bolt by positions: if bolt was at position , it moves to .
ByteGuy has forgotten the combination. A 3D scanner lets him read the current position of every hidden bolt, and the lock is built so that exactly one final knob configuration opens it.
Given the current knob positions, the current bolt positions, and the coupling values , output the knob configuration that opens the lock.
Input
The first line contains two integers: the number of knobs with , and the prime number of positions with .
The second line contains integers in the range : the current positions of the knobs.
The third line contains integers in the range : the current positions of the bolts.
Each of the next lines describes one knob. Line contains integers with .
Output
Output one line with integers in the range , separated by single spaces: the final knob positions that open the lock.