Dreisam Equations |
During excavations in the Dreisamwüste, a desert on some far away and probably uncivilized planet, sheets of paper containing mysterious symbols had been found. After a long investigation, the project scientists have concluded that the symbols might be parts of equations. If this were true, it would be proof that the Dreisamwüste was civilized a long long time ago.
The problem, however, is that the only symbols found on the sheets are digits, parantheses and equality signs. There is strong evidence that the people living in the Dreisamwüste knew only of three arithmetic operations: addition, subtraction, and multiplication. It is also known that the people of the Dreisamwüste did not have prioritization rules for arithmetic operations - they evaluate all terms strictly left to right. For example, for them the term 3 + 3 * 5 would be equal to 30, and not 18.
But currently, the sheets do not contain any arithmetic operators. So if the hypothesis is true, and the numbers on the sheets form equations, then the operators must have faded away over time.
You are the computer expert who is supposed to find out whether the hypothesis is sensible or not. For some given equations (without arithmetic operators) you must find out if there is a possibility to place +, -, and * in the expression, so that it yields a valid equation. For example, on one sheet, the string ``18=7 (5 3) 2" has been discovered. Here, one possible solution is ``18=7+(5-3)*2". But if there was a sheet containing ``5=3 3", then this would mean that the Dreisamwüste people did not mean an equation when writing this.
The line containing only the number 0 terminates the input, it should not be processed.
If there is no way to insert operators to make the equation valid, then output the line ``Impossible.".
Output one blank line after each test case.
18 = 7 (5 3) 2 30 = 3 3 5 18 = 3 3 5 5 = 3 3 0
Equation #1: 18=7+(5-3)*2 Equation #2: 30=3+3*5 Equation #3: Impossible Equation #4: Impossible