var
sum, prod, count: integer;
tmp: string;
begin
count := 0;
for var i := 0 to 999999 do
begin
sum := 0;
prod := 1;
tmp := i.tostring;
for var j := 1 to tmp.length do
begin
sum := sum + tmp[j].ToDigit;
prod := prod * tmp[j].ToDigit;
end;
if(sum = prod) then
begin
write(i, ' ');
count := count + 1;
end;
end;
write('Всего таких билетов: ', count);
end.