Alien Communication Masterclass

Time limit3sMemory limit256 MB

Summary
Given true bases and false bases, output a fixed-form product-of-factors equation that holds only for the true bases in that numeral system.
Level

Easy3 of 10

Topics
Math, Implementation, String
Solved
No attempts yet

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 a1,a2,…,ana_1, a_2, \ldots, a_n but false in the numeral systems with bases b1,b2,…,bmb_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 nn and mm (1≤n,m≤81 \le n, m \le 8).

The second line contains the nn true bases a1,a2,…,ana_1, a_2, \ldots, a_n.

The third line contains the mm false bases b1,b2,…,bmb_1, b_2, \ldots, b_m.

All of a1,…,an,b1,…,bma_1, \ldots, a_n, b_1, \ldots, b_m are distinct and lie between 22 and 1010, inclusive.

Output

In base xx the string 10 has the value xx, so it denotes the numeral-system base itself. Therefore the factor (10−1−⋯−1⏟ai ones)(10\underbrace{-1-\cdots-1}_{a_i\ \text{ones}}) evaluates to x−aix - a_i in base xx, and the product of these factors over all true bases equals ∏i=1n(x−ai)\prod_{i=1}^{n}(x - a_i). This product is 00 exactly when the base xx is one of a1,…,ana_1, \ldots, a_n and nonzero for every other base; setting it equal to 00 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 a1<a2<⋯<ana_1 < a_2 < \cdots < a_n.
  2. For each aia_i write the factor (10-1-...-1) containing exactly aia_i subtracted 1s (for example ai=2a_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 =.

Examples3

  1. Example 1

    Input
    1 2
    2
    3 9
    
    Expected output
    (10-1-1)=0
    
  2. Example 2

    Input
    2 2
    9 10
    2 3
    
    Expected output
    (10-1-1-1-1-1-1-1-1-1)*(10-1-1-1-1-1-1-1-1-1-1)=0
    
  3. Example 3

    Input
    1 1
    5
    7
    
    Expected output
    (10-1-1-1-1-1)=0