Alien Communication Masterclass

Time limit3sMemory limit256 MB

Problem

Andrea is a famous science-fiction writer who runs masterclasses for her readers. Her most popular course teaches how to behave when you encounter alien life forms, or at least alien artifacts.

One lecture is about extracting useful information from aliens' writings. Andrea explains that, from an alien mathematical formula, one can deduce the base of the numeral system the aliens use, which in turn hints at their biology. (For example, we use base 10 because we have ten fingers on our hands.)

Assume, for simplicity, that aliens use the same digits we do, and that they write addition, subtraction, multiplication, parentheses, and equality exactly as we do.

For her lecture Andrea wants a mathematical equality that is true in the numeral systems with bases $a_1, a_2, \ldots, a_n$ but false in the numeral systems with bases $b_1, b_2, \ldots, b_m$. To make the answer unique, build the equality in the fixed canonical form described in the Output section.

Input

The first line contains two integers $n$ and $m$ ($1 \le n, m \le 8$).

The second line contains the $n$ true bases $a_1, a_2, \ldots, a_n$.

The third line contains the $m$ false bases $b_1, b_2, \ldots, b_m$.

All of $a_1, \ldots, a_n, b_1, \ldots, b_m$ are distinct and lie between $2$ and $10$, inclusive.

Output

In base $x$ the string 10 has the value $x$, so it denotes the numeral-system base itself. Therefore the factor $(10\underbrace{-1-\cdots-1}{a_i\ \text{ones}})$ evaluates to $x - a_i$ in base $x$, and the product of these factors over all true bases equals $\prod{i=1}^{n}(x - a_i)$. This product is $0$ exactly when the base $x$ is one of $a_1, \ldots, a_n$ and nonzero for every other base; setting it equal to $0$ gives an equality that holds precisely in the true bases (and, because the true and false bases are distinct, in none of the false bases).

Output exactly this canonical equality, constructed as follows:

  1. Sort the true bases in increasing order $a_1 < a_2 < \cdots < a_n$.
  2. For each $a_i$ write the factor (10-1-...-1) containing exactly $a_i$ subtracted 1s (for example $a_i = 2$ gives (10-1-1)).
  3. Join the factors with * and append =0.

Print the whole equality on a single line with no spaces. Use only the characters 0, 1, (, ), -, *, and =.