type mn=set of char; var f1,f2,t1,t2:text; s,sl,sl1:string; i,st,k:byte; fl:boolean; begin assign(f1,'input.txt'); assign(f2,'output.txt'); assign(t1,'1.txt'); assign(t2,'2.txt'); rewrite(t1); rewrite(t2); reset(f1); st:=0; while not eof(f1) do begin readln(f1,s); if s='' then st:=1; if st=0 then begin s:=s+' '; i:=1; while i<=length(s) do begin sl:=''; while [s[i]]*['A'..'Z']<>[] do begin sl:=sl+s[i]; inc(i); end; if sl<>'' then writeln(t1,sl); inc(i); end; end; end; close(f1); reset(f1); st:=0; while not eof(f1) do begin readln(f1,s); if s='' then st:=1; if st=1 then begin s:=s+' '; i:=1; while i<=length(s) do begin sl:=''; while [s[i]]*['A'..'Z']<>[] do begin sl:=sl+s[i]; inc(i); end; if sl<>'' then writeln(t2,sl); inc(i); end; end; end; close(f1); close(t1); close(t2); reset(t1); rewrite(f2); while not eof(t1) do begin readln(t1,sl); reset(t2); k:=0; while (not eof(t2)) and (k=0) do begin readln(t2,s); if sl=s then begin fl:=true; reset(f2); while not eof(f2) do begin readln(f2,sl1); if sl1=sl then fl:=false; end; close(f2); if fl then begin append(f2); writeln(f2,sl); close(f2); inc(k); end; end; end; end; end.