L. LCG Manipulation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Examples
Input
8
2 3 1 7 5
2 3 1 7 6
2 3 1 7 1
2 3 1 7 0
7 1 2 31 24
7 1 2 31 25
7 1 2 31 26
7 1 1 31 26
Output
1
2
0
IMPOSSIBLE
6
4
IMPOSSIBLE
2
Input
2
314159265 1234567890 2022 2147483647 2023
1234567890 314159265 2022 2147483647 2023
Output
1058977885
IMPOSSIBLE