<PREV Problem:
NEXT>
Solved by 87 users: ...
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 

Unique radix

Time limit = 2 second(s)

Memory limit = 33000 Kb

You are given set of equation of the form "X*Y=Z" or "X+Y=Z".

You have to find radix (base of number representation) for which these equations are true.

Input First line of input contains number of equations N, 0 < N ≤ 1000. Each of next N lines contains equation description of form

X*Y=Z
or
X+Y=Z
where X, Y, and Z are positive integer number representations, namely Z, Y and Z are words from B^*, B={0,1,..,9,a,..,z}. Their lengths are less than 11. Letters 'a', 'b', ..,'z' correspond to "digits" 10, 11, .. 35.

If radix can be determined uniquely, then numbers X, Y, Z do not exceed 264 — 1.

Output Output proper radix if it is unique. Output "0" if the radix does not exist. Output "-1" if it exists but not unique.

Input#1
3 
2*2=4 
25*25=625 
10+10=20

Output#1
10

Input#2
1 
2*2=5

Output#2
0

Input#3
1 
2*2=4

Output#3
-1

Author:
First Moscow Individual Programming Championship, 17 October 2004, MIPT

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 210ms

SW soft NIX
ID = 54.224.18.114