“Ancient” Calculator

Time limit1sMemory limit128 MB

Problem

Two robots travelling across an ancient wilderness uncover a buried four-function calculator. Its display is built from three seven-segment LED digits, and every calculation is done on integers (truncating where needed), so there is no decimal point.

Seven-segment display

Each digit lights a fixed number of segments:

Digit0123456789
Segments6255456376

Rules for what the display shows:

  • Numbers appear without leading zeros: 12 is shown as "12", never "012"; the value 0 is shown as a single "0".
  • A negative number lights one extra segment for the minus sign. For example, -6 lights the segments of 6 plus one; -112 lights the 9 segments of 112 plus one for the sign, so 10 in total.
  • The display can only show values from -999 to 999.

An ammeter on the display reads the total current, and every lit segment draws 5 mA. So the current of a number is 5 mA times (the sum of the segment counts of its digits, plus 1 if the number is negative). For example:

  • 798 lights 3 + 6 + 7 = 16 segments, drawing 80 mA. The values 897, 789, and -891 all draw 80 mA as well.
  • 949 draws 80 mA, 51 draws 35 mA, and 898 draws 100 mA.
  • -5 draws 30 mA and -9 draws 35 mA.

You are given three current readings X, Y, and Z (in mA): the current of the first operand, of the second operand, and of the result. The operation Op is unknown and may be any of +, -, *, or / (division truncates toward zero, and division by zero is not allowed).

Count how many distinct expressions a Op b = c satisfy all of the following:

  • a, b, and c are integers from -999 to 999, written with no leading zeros;
  • the current of a equals X, the current of b equals Y, and the current of c equals Z;
  • a Op b = c holds, and the result c stays within -999 to 999 (expressions whose result leaves this range are not counted).

Two expressions are different when they differ in the first operand, the operation, or the second operand.

Input

The input contains several test cases. Each case is a single line with three integers X, Y, and Z (0 ≤ X, Y, Z ≤ 999), separated by single spaces: the currents in mA of the first operand, the second operand, and the result. The input ends with a line that contains the single value 0.

Output

No number is ever written with a leading zero, whether as an operand or as a result. For each test case, print one line that states how many valid expressions exist and echoes the three readings, in exactly this form:

<count> solutions for X Y Z

Use the singular word solution only when the count is exactly 1 (for example, 1 solution ...); use solutions for every other count, including 0.

Hint

For the readings 80 35 100, one valid expression is 925 - 117 = 808: 925 draws 80 mA, 117 draws 35 mA, and 808 draws 100 mA. Not every input has a match — the readings 35 10 10, for instance, admit no valid expression. For each case, find every valid expression and report the total count.