#abc198d. [abc198_d]Send More Money
[abc198_d]Send More Money
Problem Statement
Given strings consisting of lowercase English letters, solve the alphametic .
Formally, determine whether there is a triple of positive integers satisfying all of the three conditions below, and find one such triple if it exists.
Here, are strings representing (without leading zeros) in base ten, respectively.
- and have the same number of characters.
- .
- The -th character of and the -th character of is the same if and only if the -th character of and the -th character of are the same.
Constraints
- Each of , , is a string of length between and (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
If there is a triple of positive integers satisfying the conditions, print one such triple, using newline as a separator. Otherwise, print UNSOLVABLE
instead.
Sample Input 1
a
b
c
Sample Output 1
1
2
3
Outputs such as will also be accepted, but will not since it violates the third condition (both a
and b
correspond to 1
).
Sample Input 2
x
x
y
Sample Output 2
1
1
2
Outputs such as will also be accepted, but will not since it violates the third condition (both and correspond to x
).
Sample Input 3
p
q
p
Sample Output 3
UNSOLVABLE
Sample Input 4
abcd
efgh
ijkl
Sample Output 4
UNSOLVABLE
Sample Input 5
send
more
money
Sample Output 5
9567
1085
10652