import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Alphametic
{
public static void main
(String[] args
) {
try (Scanner in
= new Scanner
(System.
in)) {
while (in.hasNextLine())
{
new Alphametic(in.nextLine()).print();
}
}
}
private static Pattern pat = Pattern.compile("([0-9A-Z]+)([+-\\\\*])([0-9A-Z]+)=([0-9A-Z]+)");
private final Op operator;
private final int e;
private final int[] map = new int[256];
private final boolean[] used = new boolean[10];
private Alphametic
(String exp
) {
Matcher mat = pat.matcher(exp);
this.sa = mat.group(1);
this.op = mat.group(2);
this.sb = mat.group(3);
this.sc = mat.group(4);
this.
st = new String[] { sa, sb, sc
}; switch(op)
{
case "+": operator = (a, b) -> a + b; break;
case "-": operator = (a, b) -> a - b; break;
case "*": operator = (a, b) -> a * b; break;
}
for (int i = 0; i <= 9; i++) map['0' + i] = i;
for (int i = 'A'; i <= 'Z'; i++) map[i] = i;
e
= Math.
max(Math.
max(sa.
length(), sb.
length()), sc.
length()) * 3; solve(0, new long[3], 1);
}
private void solve(int p, long[] ls, long d)
{
if (p == e)
{
if (!operator.
test(ls
[0], ls
[1], ls
[2],
Long.
MAX_VALUE)) return; for (String s
: st
) if (map
[s.
charAt(0)] <= 0) return; result
= Arrays.
copyOf(result, result.
length + 1); result
[result.
length - 1] = String.
format("%d%s%d=%d", ls
[0], op, ls
[1], ls
[2]); return;
}
int i = p / 3;
int j = p % 3;
if (p > 0 && j == 0)
{
d *= 10;
if (!operator.test(ls[0], ls[1], ls[2], d)) return;
}
int n = ch(st[j], i);
long l = ls[j];
if (n >= 'A' && n <= 'Z')
{
for (int k = 0; k < 10; k++)
{
if (used[k]) continue;
used[k] = true;
map[n] = k;
ls[j] = l + k * d;
solve(p + 1, ls, d);
used[k] = false;
}
map[n] = n;
}
else
{
ls[j] += n * d;
solve(p + 1, ls, d);
}
ls[j] = l;
}
private int ch
(String s,
int i
) {
return s.length() <= i ? 0 : map[s.charAt(s.length() - i - 1)];
}
void print()
{
System.
out.
printf("%s%s%s=%s%n", sa, op, sb, sc
); }
private interface Op
{
long op(long a, long b);
default boolean test(long a, long b, long c, long d)
{
return Math.
abs(op
(a, b
) - c
) % d
== 0; }
}
}
aW1wb3J0IGphdmEudXRpbC5BcnJheXM7CmltcG9ydCBqYXZhLnV0aWwuU2Nhbm5lcjsKaW1wb3J0IGphdmEudXRpbC5yZWdleC5NYXRjaGVyOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4LlBhdHRlcm47CgpjbGFzcyBBbHBoYW1ldGljCnsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpCiAgICB7CiAgICAgICAgdHJ5IChTY2FubmVyIGluID0gbmV3IFNjYW5uZXIoU3lzdGVtLmluKSkKICAgICAgICB7CiAgICAgICAgICAgIHdoaWxlIChpbi5oYXNOZXh0TGluZSgpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBuZXcgQWxwaGFtZXRpYyhpbi5uZXh0TGluZSgpKS5wcmludCgpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIHByaXZhdGUgc3RhdGljIFBhdHRlcm4gcGF0ID0gUGF0dGVybi5jb21waWxlKCIoWzAtOUEtWl0rKShbKy1cXFxcKl0pKFswLTlBLVpdKyk9KFswLTlBLVpdKykiKTsKICAgIHByaXZhdGUgZmluYWwgU3RyaW5nIHNhOwogICAgcHJpdmF0ZSBmaW5hbCBTdHJpbmcgc2I7CiAgICBwcml2YXRlIGZpbmFsIFN0cmluZyBzYzsKICAgIHByaXZhdGUgZmluYWwgU3RyaW5nIG9wOwogICAgcHJpdmF0ZSBmaW5hbCBTdHJpbmdbXSBzdDsKICAgIHByaXZhdGUgZmluYWwgT3Agb3BlcmF0b3I7CiAgICBwcml2YXRlIGZpbmFsIGludCBlOwoKICAgIHByaXZhdGUgZmluYWwgaW50W10gbWFwID0gbmV3IGludFsyNTZdOwogICAgcHJpdmF0ZSBmaW5hbCBib29sZWFuW10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wogICAgICAgIHNvbHZlKDAsIG5ldyBsb25nWzNdLCAxKTsKICAgIH0KCiAgICBwcml2YXRlIHZvaWQgc29sdmUoaW50IHAsIGxvbmdbXSBscywgbG9uZyBkKQogICAgewogICAgICAgIGlmIChwID09IGUpCiAgICAgICAgewogICAgICAgICAgICBpZiAoIW9wZXJhdG9yLnRlc3QobHNbMF0sIGxzWzFdLCBsc1syXSwgTG9uZy5NQVhfVkFMVUUpKSByZXR1cm47CiAgICAgICAgICAgIGZvciAoU3RyaW5nIHMgOiBzdCkgaWYgKG1hcFtzLmNoYXJBdCgwKV0gPD0gMCkgcmV0dXJuOwogICAgICAgICAgICByZXN1bHQgPSBBcnJheXMuY29weU9mKHJlc3VsdCwgcmVzdWx0Lmxlbmd0aCArIDEpOwogICAgICAgICAgICByZXN1bHRbcmVzdWx0Lmxlbmd0aCAtIDFdID0gU3RyaW5nLmZvcm1hdCgiJWQlcyVkPSVkIiwgbHNbMF0sIG9wLCBsc1sxXSwgbHNbMl0pOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfQoKICAgICAgICBpbnQgaSA9IHAgLyAzOwogICAgICAgIGludCBqID0gcCAlIDM7CiAgICAgICAgaWYgKHAgPiAwICYmIGogPT0gMCkKICAgICAgICB7CiAgICAgICAgICAgIGQgKj0gMTA7CiAgICAgICAgICAgIGlmICghb3BlcmF0b3IudGVzdChsc1swXSwgbHNbMV0sIGxzWzJdLCBkKSkgcmV0dXJuOwogICAgICAgIH0KCiAgICAgICAgaW50IG4gPSBjaChzdFtqXSwgaSk7CiAgICAgICAgbG9uZyBsID0gbHNbal07CgogICAgICAgIGlmIChuID49ICdBJyAmJiBuIDw9ICdaJykKICAgICAgICB7CiAgICAgICAgICAgIGZvciAoaW50IGsgPSAwOyBrIDwgMTA7IGsrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYgKHVzZWRba10pIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgdXNlZFtrXSA9IHRydWU7CiAgICAgICAgICAgICAgICBtYXBbbl0gPSBrOwogICAgICAgICAgICAgICAgbHNbal0gPSBsICsgayAqIGQ7CiAgICAgICAgICAgICAgICBzb2x2ZShwICsgMSwgbHMsIGQpOwogICAgICAgICAgICAgICAgdXNlZFtrXSA9IGZhbHNlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG1hcFtuXSA9IG47CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGxzW2pdICs9IG4gKiBkOwogICAgICAgICAgICBzb2x2ZShwICsgMSwgbHMsIGQpOwogICAgICAgIH0KICAgICAgICBsc1tqXSA9IGw7CiAgICB9CgogICAgcHJpdmF0ZSBpbnQgY2goU3RyaW5nIHMsIGludCBpKQogICAgewogICAgICAgIHJldHVybiBzLmxlbmd0aCgpIDw9IGkgPyAwIDogbWFwW3MuY2hhckF0KHMubGVuZ3RoKCkgLSBpIC0gMSldOwogICAgfQoKICAgIHZvaWQgcHJpbnQoKQogICAgewogICAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCIlcyVzJXM9JXMlbiIsIHNhLCBvcCwgc2IsIHNjKTsKICAgICAgICBmb3IgKFN0cmluZyBzIDogcmVzdWx0KSBTeXN0ZW0ub3V0LnByaW50bG4ocyk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCk7CiAgICB9CgogICAgcHJpdmF0ZSBpbnRlcmZhY2UgT3AKICAgIHsKICAgICAgICBsb25nIG9wKGxvbmcgYSwgbG9uZyBiKTsKCiAgICAgICAgZGVmYXVsdCBib29sZWFuIHRlc3QobG9uZyBhLCBsb25nIGIsIGxvbmcgYywgbG9uZyBkKQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIE1hdGguYWJzKG9wKGEsIGIpIC0gYykgJSBkID09IDA7CiAgICAgICAgfQogICAgfQp9Cg==