uses crt;
const n=30;
const k=10;
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;
    i:integer;

procedure preobr(var s:string);
begin
s:=s[length(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:='';
for i:=1 to l do
begin
if a[i]=' ' then
  begin
  if (s1<>sn) then
  begin
  preobr(s1);
  write(s1,'  ');
  end;
  s1:='';
  end
else
s1:=s1+a[i];
end;
end;



begin
clrscr;
vvod(a,m);
vivod(a,m);
readln;
readln;
end.

