
program pr_2;
uses crt;
const n=50;
const k=8;
type posl=array[1..n*k] of char;
var a:posl;
    m:integer;


procedure vvod(var a:posl;var l:integer);
var c:char;
begin
writeln('vvedite posl');
a[1]:=' ';
l:=2;
read(c);
a[l]:=c;
while c<>'.' do
begin
read(c);
l:=l+1;
if (a[l-1]=' ') and (c=' ') then l:=l-1
  else a[l]:=c;
end;
end;

procedure vivod(var a:posl;l:integer);
var sn,s1:string;
    q,i:integer;

procedure preobr(var s:string);
var i:integer;
begin
i:=2;
while i<length(s) do
if  s[i]=s[1] then s:=copy(s,0,i-1)+copy(s,i+1,length(s)-i)
 else i:=i+1;
if (s[length(s)]=s[1]) and (length( s)<>1) then s:=copy(s,0,length(s)-1);

end;


begin
i:=l;
while a[i]<>' ' do
i:=i-1;

sn:='';
for i:=l-1 downto i+1 do
sn:=a[i]+sn;

s1:='';
q:=0;
for i:=1 to l do
begin
if a[i]=' ' then
  begin
  if (s1<>sn) then
  begin
  preobr(s1);
  write(s1,'  ');
  q:=9;
  end;
  s1:='';
  end
else
s1:=s1+a[i];
end;
if q=0 then writeln('net sovpadenii');
end;



begin
repeat
clrscr;
vvod(a,m);
vivod(a,m);
writeln;
writeln('repeat?');
until readkey='n';
end.