Not an official ACM page
[Problem B | 1995 Regional problem set | My ACM problem archive | my home page]

Problem A -- Long Multiplication -- Filename LONGMULT

In traditional "long multiplication" we determine the product of two integers, x and y, by multiplying x and the individual digits of y, in turn, starting with the units digit. The results of these multiplications are arranged appropriately and added, yielding the completed product.

The representation of these operations is usually done in a particular manner. Consider the multiplication of 123 by 95:
        123
         95
        ---
        615
      1107
      -----
      11685

The numbers to be multiplied, x and y, are each displayed on a separate line, followed by a horizontal line. The results of multiplying each digit of y by x are then displayed on separate lines, followed by another horizontal line, and then the final product. In this problem you are to perform a sequence of such multiplications, displaying the results in this traditional representation.

Input

Each line of the input data, except the last, will contain two integers, x and y, separated by whitespace (one or more blanks and tab characters). Whitespace may also precede the first integer and follow the second integer. Each integer will have no more than 10 digits. The last line of the input data will contain only whitespace, and marks the end of the input.

Output

For each pair of integers (that is, each input line except the last), perform the multiplication of x by y, displaying the results in the form shown above and in the examples shown below. Follow the output for each multiplication by a blank line. If y contains only a single significant digit, omit the second horizontal line and the sum (since in that case it would be superfluous). Display 0 digits only when they are significant.

The number of hyphens in the first horizontal line should be the same as the number of digits in the larger of x and y. The number of hyphens in the second horizontal line, if it is produced, should be the same as the number of digits in the product of x and y.

Sample solution

Example Input

   4 7
135  46
    12345   862
this line is blank


Expected Output

                   4
                   7
                   -
                  28

                 135
                  46
                 ---
                 810
                540
                ----
                6210

               12345
                 862
               -----
               24690
              74070
             98760
            --------
            10641390

This page maintained by Ed Karrels.
Last updated September 20, 1999