function solve(s) {
var k = s.match(/\w/g).filter(function (x, i, a) {return a.indexOf(x) === i})
var w = s.match(/\w+/g).map(function (x) {return x})
var f = ''
f += 'var ' +k.join(', ')+ ';\n'
f += 'var ' +w.join(', ')+ ';\n'
f += k.join(' = ')+ ' = 0;\n'
k.forEach(function (x) {
var n = w.some(function (y) { return y.startsWith(x) && x!=y }) ? 1 : 0
f += 'for (' +x+ ' = ' +n+ '; '+x+' < 10; ++'+x+') {\n'
})
k.forEach(function (x) {
f += 'if (' +k.filter(function (y) { return x != y }).map(function (y) { return x+ '==' +y }).join('||')+ ') continue;\n'
})
w.forEach(function (x) {
f += x+ ' = ' +x.split('').reverse().map(function (y, i) { return i == 0 ? y : Math.pow(10, i)+ '*' +y}).reverse().join(' + ')+ ';\n'
})
f += 'if (' +s+ ') return [' +w.join(', ')+ '];'
f += '}'.repeat(k.length) + '\n'
var e = new Function(f)()
return w.reduce(function (l, r, i) { return l.replace(r, e[i]) }, s)
}
ZnVuY3Rpb24gc29sdmUocykgewoKCXZhciBrID0gcy5tYXRjaCgvXHcvZykuZmlsdGVyKGZ1bmN0aW9uICh4LCBpLCBhKSB7cmV0dXJuIGEuaW5kZXhPZih4KSA9PT0gaX0pCgl2YXIgdyA9IHMubWF0Y2goL1x3Ky9nKS5tYXAoZnVuY3Rpb24gKHgpIHtyZXR1cm4geH0pCgoJdmFyIGYgPSAnJwoJZiArPSAndmFyICcgK2suam9pbignLCAnKSsgJztcbicKCWYgKz0gJ3ZhciAnICt3LmpvaW4oJywgJykrICc7XG4nCglmICs9IGsuam9pbignID0gJykrICcgPSAwO1xuJwoJay5mb3JFYWNoKGZ1bmN0aW9uICh4KSB7IAoJCXZhciBuID0gdy5zb21lKGZ1bmN0aW9uICh5KSB7IHJldHVybiB5LnN0YXJ0c1dpdGgoeCkgJiYgeCE9eSB9KSA/IDEgOiAwCgkJZiArPSAnZm9yICgnICt4KyAnID0gJyArbisgJzsgJyt4KycgPCAxMDsgKysnK3grJykge1xuJyAKC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