program ghillie;
var g:text;
a,j:array[0..10000]of longint;
bo:array[0..10000]of longint;
t,k,m,n,x,y,w:longint;
function mis(i,t:longint):longint;
var k,mi:longint;
begin
mi:=1;
if w=1 then exit else w:=0;
for k:=1 to t do
begin
mi:=mi*i;
if mi>255 then
begin
w:=1;
exit;
end;
end;
mis:=mi;
end;
procedure pp(i:longint);
var p:longint;
begin
w:=0;
p:=mis(i mod 10,t+1)+mis((i div 10)mod 10,t+1)+mis(i div 100,t+1);
if w=1 then exit;
if bo[p]=1 then
begin
inc(y);
j[y]:=p;
end;
end;
begin
assign(g,'ghillie.in');
reset(g);
readln(g,n);
repeat
inc(x);
read(g,a[x]);
bo[a[x]]:=1;
until eof(g);
close(g);
for t:=1 to n do
begin
for k:=1 to x do
if bo[a[k]]=1 then pp(a[k]);
if y>0 then
for k:=1 to y do
bo[j[k]]:=0;
y:=0;
end;
assign(g,'ghillie.out');
rewrite(g);
for t:=1 to 255 do
if bo[t]=1 then write(g,t,' ');
writeln(g);
close(g);
end.