import re
from itertools import product

n = int(input())
inp = [input() for _ in range(n)]

w = max(len(e) for e in inp)

s = '\n'.join(inp)
fill = lambda st: list(map(lambda x: int(x) if x.isdigit() else None, re.sub(r'\s+', '', st)))
a, b, c = re.split('\n-+\n', s)
fst, snd = a.split('\nx')
fst = fill(fst)
snd = fill(snd)
inter = [fill(l) for l in b.split('\n')]


res = fill(c)
fst_unk = [i for i in range(len(fst)) if fst[i] is None]
snd_unk = [i for i in range(len(snd)) if snd[i] is None]

is_ok = lambda r, lst: all(x == int(lst[i]) for i, x in enumerate(r) if x is not None)
    
if all(x is None for x in fst) and all(x is None for x in snd) and all(all(x is None for x in e) for e in inter) and all(not x is None for x in res):
    pr = int(c)
    
    l = len(fst)

    for d in range(10**(l - 1), 10**l - 1):
        if pr % d == 0:
            m = pr // d
            if len(str(m)) == len(snd):
                coef = list(map(int, str(m)))
                ans = []
                ans.append(str(d).rjust(w, ' '))
                ans.append("x" + str(m).rjust(w - 1, ' '))
                ans.append('-' * w)
                for i in range(len(inter)):
                    v = coef[-1 - i] * d
                    ans.append((str(v) + '0' * i).rjust(w, ' '))
                ans.append('-' * w)
                ans.append(c)
                print('\n'.join(ans))
                break
    

    exit()
for f in product(range(10), repeat=len(fst_unk)):
    for s in product(range(10), repeat=len(snd_unk)):        
        f_c, s_c = fst[:], snd[:]
        for i, v in enumerate(f):
            f_c[fst_unk[i]] = v
        for j, v in enumerate(s):
            s_c[snd_unk[j]] = v
        fst_v = int(''.join(map(str, f_c)))
        snd_v = int(''.join(map(str, s_c)))
        prod = list(map(int, str(fst_v * snd_v)))
        _len = len(prod)
        if _len == len(res) and is_ok(res, prod): 
            ok = True
            steps = []
            for i, ele in enumerate(inter):
                step = s_c[-1-i] * fst_v
                print(step)
                if step != 0:
                    arr = list(map(int, str(step))) + [0] * i
                else:
                    arr = [0] * 2
                steps.append(arr)
                if len(ele) != len(arr) or not is_ok(ele, arr):
                    ok = False
                    break
            if ok:
                print(f_c, s_c, steps, prod)
                ans = []
                ans.append(''.join(map(str, f_c)).rjust(w, ' '))
                ans.append("x" + ''.join(map(str, s_c)).rjust(w - 1, ' '))
                ans.append('-' * w)
                for e in steps:
                    ans.append(''.join(map(str, e)).rjust(w, ' '))
                ans.append('-' * w)
                ans.append(''.join(map(str, prod)).rjust(w, ' '))
                print('\n'.join(ans))
                break

        

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: