#P5758. Deciphering the Ancient Mei Operators

    ID: 18986 Type: Default 1000ms 256MiB

Deciphering the Ancient Mei Operators

Deciphering the Ancient Mei Operators

The ancient Mei civilization used a set of 13 symbols to denote the digits and operators we use today. They used the letters a through m to represent 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, * and = (in some order). Archaeologists have recovered several equations written in these ancient symbols. It is known that:

  • Each equation contains exactly one occurrence of the symbol for =.
  • Both sides of the equation are infix arithmetic expressions that follow normal operator precedence (multiplication before addition).
  • All numbers are in base‑10 and written without extraneous leading zeros (except for the number 0 itself) and the expressions are valid when interpreted with the proper mapping.

Your task is to decipher the mapping between the ancient symbols (letters a to m) and the modern digits and operators. Under the unique correct mapping, after replacing every letter with its modern counterpart in each equation, the equation will be valid; that is, both sides evaluate to the same number.

Note on arithmetic: The expressions use standard operator precedence: multiplication (*) is computed before addition (+). For example, the expression \( 12+3\times4 \) should be interpreted as \(12+(3\times4)=24\).

inputFormat

The first line contains an integer n (n ≥ 1), the number of equations.

Each of the next n lines contains a string consisting only of the lowercase letters from a to m representing an equation in ancient Mei symbols. Each equation is guaranteed to have exactly one occurrence of the symbol that represents = under the correct mapping.

outputFormat

Output the deciphered mapping as 13 pairs in a single line, separated by a space. Each pair is in the format letter:modern, where the letters are ordered lexicographically from a to m.

If there are multiple solutions, output any one of them.

sample

3
ackdmaf
cldkemab
hkmiaf
a:1 b:0 c:2 d:3 e:4 f:5 g:6 h:7 i:8 j:9 k:+ l:* m:=