uses crt;
type mang=array[1..500] of integer;
var a,b,c,d:mang;
i,j,n,m,k,p:integer;kt:boolean;
begin
clrscr;
write('Spt A =');readln(n) ;
for i:=1 to n do
begin
write('a[',i,']= ');
readln(a[i]);
end;
write('Spt B =');readln(m);
for i:=1 to m do
begin
write('b[',i,']= ');
readln(b[i]);
end;
p:=0;
writeln('Giao cua A va B la');
for i:=1 to n do
for j:=1 to m do
if (a[i]=b[j]) then
begin
kt:=true;
for k:=1 to p do
if a[i]=c[k] then begin kt:=false;break;end;
if kt=true then begin inc(p); c[p]:=a[i]; end;
break;
end;
for i:=1 to p do write(c[i],' ');
writeln;
writeln('Hop cua A va B');
p:=0;
for i:=1 to n do
begin
kt:=true;
for j:=1 to p do
if a[i]=d[j] then begin kt:=false;break;end;
if kt=true then begin inc(p); d[p]:=a[i]; end;
end;
for i:=1 to m do
begin
kt:=true;
for j:=1 to p do
if b[i]=d[j] then begin kt:=false;break;end;
if kt=true then begin inc(p); d[p]:=b[i]; end;
end;
for i:=1 to p do write(d[i],' ');
readln;
end.