atcoder#ABC198D. [ABC198D] Send More Money

[ABC198D] Send More Money

Score : 400400 points

Problem Statement

Given strings S1,S2,S3S_1,S_2,S_3 consisting of lowercase English letters, solve the alphametic S1+S2=S3S_1+S_2=S_3.

Formally, determine whether there is a triple of positive integers N1,N2,N3N_1, N_2, N_3 satisfying all of the three conditions below, and find one such triple if it exists. Here, N1,N2,N3N'_1, N'_2, N'_3 are strings representing N1,N2,N3N_1, N_2, N_3 (without leading zeros) in base ten, respectively.

  • NiN'_i and SiS_i have the same number of characters.
  • N1+N2=N3N_1+N_2=N_3.
  • The xx-th character of SiS_i and the yy-th character of SjS_j is the same if and only if the xx-th character of NiN'_i and the yy-th character of NjN'_j are the same.

Constraints

  • Each of S1S_1, S2S_2, S3S_3 is a string of length between 11 and 1010 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S1S_1

S2S_2

S3S_3

Output

If there is a triple of positive integers N1,N2,N3N_1, N_2, N_3 satisfying the conditions, print one such triple, using newline as a separator. Otherwise, print UNSOLVABLE instead.

a
b
c
1
2
3

Outputs such as (N1,N2,N3)=(4,5,9)(N_1, N_2, N_3) = (4,5,9) will also be accepted, but (1,1,2)(1,1,2) will not since it violates the third condition (both a and b correspond to 1).

x
x
y
1
1
2

Outputs such as (N1,N2,N3)=(3,3,6)(N_1, N_2, N_3) = (3,3,6) will also be accepted, but (1,2,3)(1,2,3) will not since it violates the third condition (both 11 and 22 correspond to x).

p
q
p
UNSOLVABLE
abcd
efgh
ijkl
UNSOLVABLE
send
more
money
9567
1085
10652