Elementary Math
Time limit10sMemory limit256 MB
Assign +, -, or * to each of n given pairs so all results differ, choosing the lexicographically smallest valid assignment.
Problem
Ellen teaches elementary math and the final exam is coming up. The exam has questions. In each question a student adds (+), subtracts (-), or multiplies (*) a pair of integers.
Ellen has already picked the pairs. What is left is deciding which operation goes with each pair. So the students do not get bored, all results must be different.
Help Ellen prepare the exam.
Input
The first line contains the number of pairs ().
Each of the next lines contains the two integers and of one pair, separated by a space ().
Output
If an assignment exists, print lines in the same order as the input. Line has the form a op b = c, where op is one of +, -, * and c is the result of that operation. Separate the parts with single spaces. The results must all be different.
Several assignments can satisfy this, so print exactly one of them. Read the chosen operators in input order as a string and print the assignment whose string is smallest in the order +, -, *. Equivalently, go pair by pair from the first one and use + whenever the remaining pairs can still be given distinct results, otherwise -, otherwise *.
If no assignment makes the results different, print impossible.