#P9888. Restore Original Numbers from Magic Multiplication

    ID: 23033 Type: Default 1000ms 256MiB

Restore Original Numbers from Magic Multiplication

Restore Original Numbers from Magic Multiplication

BaoBao has discovered a mysterious binary operation between two positive integers A and B, defined as follows:

Let A be an n-digit number represented as \(a_1a_2\dots a_n\) and B be an m-digit number represented as \(b_1b_2\dots b_m\). Then the operation \(\otimes\) is defined by

\[ A\otimes B = \text{concat}(a_1b_1, a_1b_2, \dots, a_1b_m, a_2b_1, \dots, a_nb_m), \]

where for each product \(a_i\times b_j\), the result is considered as a string (if the product is positive, it is written without leading zeros; if the product is 0, it is represented as "0"). The concatenation is performed in the order shown above.

For example, since \(2\times4=8\), \(2\times5=10\), \(3\times4=12\), \(3\times5=15\), we have:

\[ 23\otimes45 = \texttt{8\;10\;12\;15} = 8101215. \]

BaoBao now gives you the result of a \(\otimes\) operation and the numbers of digits in the two original integers. Your task is to help him restore the two original integers A and B.

Note: Both numbers are positive integers. Their representations do not contain leading zeros (i.e. the first digit is nonzero), but other digits may be zero.

inputFormat

The input consists of two lines:

  1. The first line contains a string S, which is the result of the \(\otimes\) operation.
  2. The second line contains two integers \(n\) and \(m\), representing the number of digits in A and B respectively.

It is guaranteed that \(S\) can be segmented into exactly \(n \times m\) parts where each part is either a one-digit or two-digit number as defined in the description.

outputFormat

Output the two original integers A and B (without spaces within the numbers) separated by a space. It is guaranteed that a unique solution exists for the given input.

sample

8101215
2 2
23 45