var a,b:array of integer;
i,n,s,p:integer;
begin
read(n);
setlength(a,n);
writeln;
for i:=0 to n-1 do begin
read(a[i]);
if a[i]<>0 then inc(s);
end;
setlength(b,s);
for i:=0 to n-1 do begin
if a[i]<>0 then begin
b[p]:=a[i];
inc(p);
end;
end;
writeln;
for p:=0 to s-1 do write(b[p],' ');
end.