Bender
Time limit2sMemory limit512 MB
Choose parameters a, b, c of a linear congruential sequence so that n swaps of adjacent cups move the ball from position r to position l, or report Impossible.
- Level
Hard8 of 10
- Topics
- Brute force, Implementation, Simulation, Math
- Solved
- No attempts yet
Problem
Robot Bender decided to open an attraction called <> to get rich. The attraction works as follows. Bender hides a ball under one of identical cups placed at positions 1 through , then quickly swaps some pairs of cups times, and after that asks you to guess which cup the ball is under now.
Bender is a robot, so he acts according to a fixed program. Bender builds a sequence of integers , where and for .
At step , Bender swaps the cups at positions and .
At the start, the robot hides the ball under the cup at position . Bender wants the ball to end up under the cup at position after swaps.
Find , , and such that the cup with the ball moves from position to position .
Input
The single line of the input file contains four integers , , , and (; ; ).
Output
If no such numbers exist, print the single word <<Impossible>> to the output file. Otherwise, print three nonnegative integers , , and . The numbers must not exceed .