Initially, Andrei had two sequences and of elements each. The sequence contained natural numbers , while the sequence had numbers with the following property: for each , , and .
One morning, Andrei realized that some numbers had been smudged and were unreadable!
Since Andrei wants both sequences and to be readable from the beginning to the end, he asks you to help him reconstruct the sequences.
Input data
The first line contains natural numbers and , and the second and third lines of the input contain the sequences and , respectively. If a number at position is , it means that number is unreadable. It is guaranteed that the readable numbers respect the given property.
Output data
The first line will contain the readable sequence from start to finish, and the second line will contain the readable sequence from start to finish. Since Andrei is a thoughtful boy, he will accept any solution you find, as long as it respects the rule of the sequences.
Constraints and clarifications
- For points,
- It is guaranteed that a solution exists
- During the contest "RoAlgo Contest #2", there was no test with id 14. It was added later so that only the solution with the best complexity would score 100 points
Example 1
stdin
3 6
1 -1 4
-1 -1 -1
stdout
1 4 4
1 4 4
Explanation
- (mod )
- (mod )
Therefore, these sequences respect the property.
Example 2
stdin
3 7
-1 -1 5
-1 -1 6
stdout
2 2 5
2 4 6
Explanation
- (mod )
- (mod )
Therefore, these sequences respect the property.