program r937;
uses crt;
var s:set of 0..9;
procedure take(n:integer);
begin
s:=s-[n];
end;
procedure putback(n:integer);
begin
s:=s+[n];
end;
procedure rebus1;
var o,d,i,n,p,a,t,b:integer;
begin
writeln;
writeln('otvety1');
o:=1;
b:=0;
s:=[2..9];
repeat
for d :=0 to 9 do if d in s then begin
take(d); for i:=0 to 9 do if i in s then begin
take(i); for n:=2 to 9do
if (n<>5) and (n in s ) then begin
take(n); for p:=5 to 9 do if p in s then begin
take(p); for a:=0 to 9 do if a in s then begin
take(a); for t:=0 to 9 do if t in s then
if(5*o-p)*1000+(5*d-a)*100+(5*i-t)*10+5*n-b=0 then
write ('5*', o,d,i,n,'=',p,a,t,b,' ');
putback(a);
end;
putback(p);
end;
putback(n);
end;
putback(i);
end;
putback(d);
end;
inc(b,5);
s:=s-[5]+[0];
until b<>10;
writeln;
end;
procedure rebus4;
var v,o,l,f,i,a,t,m,r:integer;
begin
writeln;
writeln('otvety4');
s:=[0..9];
for v:=1 to 8 do
begin
take(v);
m:=v+1;
take(m);
for o :=1 to 9 do if o in s then begin
take(o);
for l:=0 to 9 do if l in s then begin
take(l);
for f:=1 to 9do
if f in s then begin
take(f); for i:=0 to 9 do if i in s then begin
take(i); for a:=0 to 9 do if a in s then begin
take(a); for t:=1 to 9 do if t in s then begin
take(t); r:=-10000+f*1000+(l+i-t)*100+(v+a-o)*10+(o+t);
if(r>=0) and(r<=9) and(r in s) then
write (v,o,l,v,o,'+',f,i,a,t,'=',m,o,t,o,r,' ');
putback(t);
end;
putback(a);
end;
putback(i);
end;
putback(f);
end;
putback(l);
end;
putback(o);
end;
putback(m);
putback(v);
end;
writeln;
end;
BEGIN
rebus1;
rebus4;
END.