Unique Solution
Time limit1sMemory limit512 MB
Given a target array a with entries -1, 0, or 1, find m and x so that only a and -a make the signed sum of x divisible by m.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Bit manipulation
- Solved
- No attempts yet
Problem
The professor is preparing a task for higher math students. The students are given integers and an integer (). The student must choose integers , each either , , or , with at least one non-zero value. The chosen integers must satisfy the condition that is divisible by .
The professor has decided that the answer is a given array of integers (, at least one of them is not ). To make checking students' solutions easier, he wants to choose integers and an integer so that his array is the only possible solution. This is impossible, because the array is always a solution too.
So the professor relaxes his requirements and wants the only two solutions to be and . Help him choose integers and an integer .
Input
The first line of input contains an integer (). The next line contains integers (). At least one of is not equal to .
Output
The first line of output must contain an integer (). The next line must contain integers (). If there are several possible answers, output any of them. It is known that the answer always exists.
Hint
In the given example, the students must choose and so that is divisible by . There are two possible solutions: , (, divisible by ) and , (, divisible by ). The professor's requirements are met.