program zad;
uses crt;
var s:string;
i:byte;
BEGIN
writeln('vvedite text:'); readln(s);
   for i:=length (s)-1 downto 1 do
      if (s[i]=' ') and ((s[i+1]=' ') or (s[i+1] in [',','.',':',';','?','!']))
      then delete(s,i,1) else if (s[i] in [',','.',':',';','?','!'])
      and (s[i+1]<>' ') then insert('',s,i+1);
   writeln(s) ;
readln;
End.