function prim(n:integer):integer;
var i,j:integer;
begin
for i:=1 to n do
if n mod i = 0 then
j:=j+1;
if j=2 then prim:=1 else
prim:=0;
end;
var
x,y:array of integer;
i,j,n,k:integer;
begin
read(n);
setlength(x,n);
writeln;
for i:=0 to n-1 do
read(x[i]);
for i:=n-1 downto 0 do
if prim(x[i])=1 then
begin
j:=j+1;
setlength(y,j);
y[j-1]:=x[i];
end;
writeln;
for i:=0 to j-1 do
write(y[i],' ');
end.